-
大小: 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开发的多人聊天室 语言C#
- WPF控件库HandyControl
- WPF
- c# wpf实现的上位机
- VisionPro控件在WPF 应用
- WPF使用MVVM
- winform实现饼状图、柱状图、折线图(
- C#中WPF联合Halcon的一个学习(解决内存
- WPF CEFSHARP 支持 MP4
- WPF贝塞尔曲线
- WPF 简单控件集
- WPF鼠标拖动控件源码
- wpf开发教程
- AduMusic迷你音乐盒WPF源码
- WPF PDF封装(放大、缩小、单页、双页
- C# .NET5.0(net core)基于WPF(XAML)开发
- WPF MVVM 基础入门
- wpf echart
- windorm 加载WPF控件 ,实现dxf文件显示
- WPF Control Development
- wpf Dock window
- WPF 隐蔽查看股票行情工具
- WPF控件库(HandyControl)
- 别踩白块wpf 源码
- WPF贪吃蛇
- WPF Task 多任务
- WPF path动画
- WPF 最基础的组件拖动、改变大小
- WPF DATAGRID 数据绑定
- WPF绘制坐标系(可放大缩小)
评论
共有 条评论