1、datetimepicker--自定义格式
按理说,datetimepicker的格式由customformat来决定就是了,但是仅仅修改customformat属性是不够的。
附上一段datetimepicker的designer.cs
this.YearDateTimePicker.CustomFormat = "yyyy"; this.YearDateTimePicker.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.YearDateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.YearDateTimePicker.Location = new System.Drawing.Point(132, 15); this.YearDateTimePicker.Margin = new System.Windows.Forms.Padding(4); this.YearDateTimePicker.Name = "YearDateTimePicker"; this.YearDateTimePicker.Size = new System.Drawing.Size(241, 30); this.YearDateTimePicker.TabIndex = 41;
这里只是修改了其customformat属性值,但是我们会发现其显示效果仍旧和原来一样。附上一个显示例子,看记录年份。
其实我们还需要进一步做一件事,就是将format的类型指向customformat。
即YearDateTimePicker.Format=DateTimePickerFormat.Custom;
YearDateTimePicker.CustomFormat="yyyy";
或者通过属性窗口来设置:
vs 之bug集(不断更新中),布布扣,bubuko.com
原文地址:http://blog.csdn.net/ztzi321/article/details/38611467