基本介绍

时间控件应用较为广泛,属性设置项也比较完善是非常好用的控件。

常设置属性、事件

CustomFormat:当Format属性设置为自定义类型时可自定义控件时间的显示格式;

Enabled:指示是否启用该控件,true为启用状态可编辑,false为禁用状态不可编辑;

MaxDate:设置控件可选择或输入的最大日期;

MinDate:设置控件可选择或输入的最小日期;

Name:指示代码中用来标识该对象的名称;

ShowUpDown:是否使用下拉日历修改日期,false为下拉日历模式,true为区域数字增减模式;

Text:与控件关联的文本,显示给用户看的内容说明;

ValueChanged事件:控件值更改时发生;

事例举例

        //切换时间调整模式及显示格式
private void btn_ChangeType_Click(object sender, EventArgs e)
{
string strValue = txt_TimeFormat.Text;
if (!string.IsNullOrWhiteSpace(strValue))
{
this.dateTimePicker1.Format = DateTimePickerFormat.Custom;
this.dateTimePicker1.CustomFormat = strValue;
this.dateTimePicker1.ShowUpDown = true; //部分时间格式转换
StringBuilder sb = new StringBuilder();
strValue = this.dateTimePicker1.Text;
if (!string.IsNullOrWhiteSpace(strValue))
{
try
{
DateTime dtime = this.dateTimePicker1.Value; if (string.IsNullOrWhiteSpace(cb_format.Text))
{
string[] strFormat = new string[cb_format.Items.Count];
for (int i = , counti = cb_format.Items.Count; i < counti; i++)
{
strFormat[i] = cb_format.Items[i].ToString();
} for (int i = , counti = strFormat.Length; i < counti; i++)
{
string str = strFormat[i]; string value1 = string.Format("【{0}→{1}】", strValue, str);
sb.AppendFormat("{0,30}{1}", value1, dtime.ToString(str)); sb.AppendLine();
sb.AppendLine(); if (i == counti - )
{
System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
int weekOfYear = gc.GetWeekOfYear(dtime, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
value1 = string.Format("【{0}→{1}】", strValue, "DayOfWeek");
sb.AppendFormat("{0,30}{1}年第{2}周", value1, dtime.Year, weekOfYear); sb.AppendLine();
sb.AppendLine();
value1 = string.Format("【{0}→{1}】", strValue, "DayOfYear");
sb.AppendFormat("{0,30}{1}年第{2}天", value1, dtime.Year, dtime.DayOfYear); sb.AppendLine();
sb.AppendLine();
value1 = string.Format("【{0}→{1}】", strValue, "Number");
sb.AppendFormat("{0,30}{1}|【基数:{2}】", value1, Helpers.UtilityHelper.DateToNumberValue(dtime, date_Base.Value), date_Base.Value);
}
} }
else
{
strValue = string.Format("【{0}→{1}】", strValue, cb_format.Text);
sb.AppendFormat("{0,30}{1}", strValue, dtime.ToString(cb_format.Text));
sb.AppendLine();
sb.AppendLine();
} txt_TiemResult.Text = sb.ToString();
}
catch (Exception ex)
{
Helpers.LogHelper.ErrorMsgRecord(string.Format("【FrmText.btn_ChangeType_Click】{0}", ex.Message), ex, Helpers.UtilityHelper.GetSerialNumber());
MessageBox.Show("时间转换报错:" + ex.Message);
}
}
}
}

时间控件的下拉日历也有比较完善的属性设置就不一一例举了,至于格式的转换目前也只是例举出了一小部分。

WinForm控件之【DateTimePicker】的更多相关文章

  1. WinForm控件使用文章收藏整理完成

    对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, 不断补充充实, 完善这方面. 基础 - 常用控件 C# WinForm开发系列 - CheckBox/Button/Lab ...

  2. C#中常见的winform控件命名规范

    我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...

  3. C# WinForm控件、自定义控件整理(大全)

    转:http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html 对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, ...

  4. C#中常见的winform控件命名规范 转

    我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...

  5. 在WPF中使用WinForm控件方法

    1.      首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2.      在要使用WinForm控 ...

  6. WPF 调用WinForm控件

    WPF可以使用WindowsFormsHost控件做为容器去显示WinForm控件,类似的用法网上到处都是,就是拖一个WindowsFormsHost控件winHost1到WPF页面上,让后设置win ...

  7. WinForm控件TreeView 只部分节点显示 CheckBox

    WinForm控件TreeView 只部分节点显示  CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...

  8. Winform控件重写

    Winform控件重写 因为最近的项目中越来越多的遇到了比较特殊的一些控件,有时候我们自己封装一下可能更加方便我们的使用,下面是我们项目中用到的,简单做一个记录. TextBox控件重写 主要的控制代 ...

  9. 通过WinForm控件创建的WPF控件无法输入的问题

    今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...

  10. c#Winform控件总结

    1. C# WinForm控件.自定义控件整理(大全) (http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html) 2. c#窗体控件用 ...

随机推荐

  1. 硬盘的结构和介绍,硬盘MBR详细介绍(超详细彩图)

    一.物理结构 1.磁道,扇区,柱面和磁头数 硬盘最基本的组成部分是由坚硬金属材料制成的涂以磁性介质的盘片,不同容量硬盘的盘片数不等.每个盘片有两面,都可记录信息.盘片被分成许多扇形的区域,每个区域叫一 ...

  2. 了解 XML 数字签名

    http://www.cnblogs.com/flyxing/articles/91734.html http://www.cnblogs.com/wuhong/archive/2010/12/20/ ...

  3. 零元学Expression Blend 4 - Chapter 3 熟悉操作第一步(制作一个猴子脸)

    原文:零元学Expression Blend 4 - Chapter 3 熟悉操作第一步(制作一个猴子脸) 本篇内容会教你如何使用笔刷.钢笔.渐层以及透明度的调整,还有如何转化图层和路径,最重要的是要 ...

  4. BackgroundWorker 简单使用教程 多个线程的创建

    原文:BackgroundWorker 简单使用教程 多个线程的创建 BackgroundWorker是一个非常不错的线程控件,能避免界面假死,让线程操作你想要做的事,它学习起来很简单,但是能实现很强 ...

  5. 从wireshark中学网络分析(一)

    http://blog.csdn.net/nk_test/article/details/56509688 http://blog.csdn.net/nk_test/article/details/5 ...

  6. 使用 Visual Studio 开发并调试 Mail Add-in (mail app for Outlook)

    准备工作 如果你的邮箱搭建在 Exchange Server 上,则可以创建邮件应用程序(Mail Add-in)来扩展Office本身的功能,使用 Office Add-in Model 开发的 M ...

  7. Globalize 1.0 发布,jQuery 的国际化插件

    分享 <关于我> 分享  [中文纪录片]互联网时代                 http://pan.baidu.com/s/1qWkJfcS 分享 <HTML开发MacOSAp ...

  8. JavaScript MVC框架PK:Angular、Backbone、CanJS与Ember(转载)

    原文地址:http://sporto.github.io/.../comparison-angular-backbone-can-ember/ 原文作者:Sebastian Porto @Twitte ...

  9. Codility------CyclicRotation

    Task description A zero-indexed array A consisting of N integers is given. Rotation of the array mea ...

  10. Codeforces Round #563 (Div. 2)A

    A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...