DateTimePicker在toolStrip控件中添加

toolStrip控件中要添加日期控件时,首先定义宏控件

  DateTimePicker BeginTime = new DateTimePicker();

然后在界面构造函数中,在目标位置插入控件

1 public JILiangTestDetailUI()
2 {
3     InitializeComponent();
4 
5     ToolStripControlHost begin = new ToolStripControlHost(BeginTime);
6 
7     this.toolStrip1.Items.Insert(13, begin);
8 }

其他控件也可以借鉴此方法插入toolStrip控件。

DateTimePicker控件如果要只使用年月,更改控件的Format属性说明格式可编辑,更改CustoMForat属性编辑格式:

1、年Format: custom CustoMForat: yyyy年
2、月 Format: custom CustoMForat: MM月
3、年月:Format: custom CustoMForat: yyyy年MM月

猜你喜欢

转载自www.cnblogs.com/ChenhaonanFamily/p/10362782.html