-
大小: 548KB文件类型: .7z金币: 1下载: 0 次发布日期: 2021-05-20
- 语言: C#
- 标签: WPF DateTimePick
资源简介
一个可以实现年月日时分秒的WPF控件,希望对学习WPF的朋友有所帮助!
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace DateTimePickerControl
{
public partial class DateTimePicker : UserControl INotifyPropertyChanged
{
public DateTimePicker()
{
InitializeComponent();
DatePickerObj.SelectedDate = DateTime.Now;
this.SendPropertyChanged(“SelectedDateTimeString“);
_selectedHour = DateTime.Now.Hour;
_selectedMinute = DateTime.Now.Minute;
_selectedSecond = DateTime.Now.Second;
_oldTextBox = _currentTextBox = TextBox_Seconds;
_currentTextBox.Background = Brushes.Pink;
}
public DateTime SelectedDateTime
{
get
{
DateTime obj = DatePickerObj.SelectedDate ?? DateTime.Now;
return obj.Add(new TimeSpan(SelectedHour - obj.Hour SelectedMinute - obj.Minute SelectedSecond - obj.Second));
}
}
public String SelectedDateTimeString
{
get
{
return SelectedDateTime.ToString(“yyyy-MM-dd HH-mm-ss“);
}
}
#region private methods
private void TextBox_Hours_GotFocus(object sender RoutedEventArgs e)
{
_oldTextBox.Background = Brushes.Transparent;
_oldTextBox = _currentTextBox = TextBox_Hours;
_currentTextBox.Background = Brushes.Pink;
}
private void TextBox_Minutes_GotFocus(object sender RoutedEventArgs e)
{
_oldTextBox.Background = Brushes.Transparent;
_oldTextBox = _currentTextBox = TextBox_Minutes;
_currentTextBox.Background = Brushes.Pink;
}
private void TextBox_Seconds_GotFocus(object sender RoutedEventArgs e)
{
_oldTextBox.Background = Brushes.Transparent;
_oldTextBox = _currentTextBox = TextBox_Seconds;
_currentTextBox.Background = Brushes.Pink;
}
private void ComboBox_DropDownClosed(object sender EventArgs e)
{
this.SendPropertyChanged(“SelectedDateTime“);
this.SendPropertyChanged(“SelectedDateTimeString“);
}
private void BTN_IncreaseTime_Click(object sender RoutedEventArgs e)
{
Int32 result;
if (Int32.TryParse(_currentTextBox.Text out result))
{
result++;
_currentTextBox.Text = result.ToString();
}
}
private void BTN_DecrementTime_Click(object sender RoutedEventArgs e)
- 上一篇:C#+串口和USB通信编程(代码)
- 下一篇:C#将txt文档中的重复记录删除。
相关资源
- WPF漂亮导航面板源码20121022.zip
- WPF异形悬浮窗体源码
- 如何在WPF应用程序中通过HttpClient调用
- wpf rtmp,rtsp 播放器
- wpf 触屏虚拟键盘支持中英文切换
- Arcgis Runtime SDK for WPF文件过大,内附网
- DynamicDataDisplay.dll
- 小人快跑WPF帧动画效果
- C# wpf combobox带treeview的自定义控件
- WPF TabControl完美样式在下方显示+完美
- 串口通信 wpf C#
- wpf游戏2048
- 骑士周游问题WPF工程
- wpf led 时钟
- WPF流程图 开发
- WPF分页控件
- C#WPF 右键菜单 显示 事件触发 测试
- WPF loading源码合集汇集好几种loading效
- wpf仿QQ好友分组
- WPF:定制Checkbox样式,让“正确”绿得
- 刘铁猛《深入浅出WPF》全套真高清视
- wpf border 边框不同颜色
- WPF复制粘贴剪切功能.rar
- C#中DataGridView控件DateTime列插入DateTi
- MVVM,WPF
- C#控制系统声音大小
- wpf 消息提示框仿QQ左下角提示框
-
xm
l文件与WPF中TreeView、Menu交互 -
WPF Application fr
amework (WAF) Nested -
Wpf 样式和模板含 fr
amework 4.5 aero2
评论
共有 条评论