我发现问题出在这里。
The Value
属性仅在以下情况下设置新值:DateTimePicker
控制可见。否则命令将被忽略。
测试用例:
不起作用:
this.picker = new DateTimePicker
{
Checked = false,
Font = new System.Drawing.Font("Verdana", 9.75F),
Format = System.Windows.Forms.DateTimePickerFormat.Time,
Location = new System.Drawing.Point(5, 5),
Name = "picker",
ShowUpDown = true,
Size = new System.Drawing.Size(120, 23),
Visible = false
};
this.Controls.Add(this.picker);
this.picker.Value = this.picker.Value.Date.AddHours(1);
this.picker.Visible = true;
Works:
this.picker = new DateTimePicker
{
Checked = false,
Font = new System.Drawing.Font("Verdana", 9.75F),
Format = System.Windows.Forms.DateTimePickerFormat.Time,
Location = new System.Drawing.Point(5, 5),
Name = "picker",
ShowUpDown = true,
Size = new System.Drawing.Size(120, 23),
Visible = false
};
this.Controls.Add(this.picker);
this.picker.Visible = true;
this.picker.Value = this.picker.Value.Date.AddHours(1);
似乎与以编程方式添加选择器没有任何关系。