Ho scoperto qual era il problema.
La proprietà Value
imposta un nuovo valore solo se il controllo DateTimePicker
è visibile. Altrimenti il comando viene ignorato.
Test case:
non funziona:
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);
non sembra avere nulla a che fare con l'aggiunta di programatically il selettore a quanto pare.
+1 perché penso di avere un problema simile. – reverendlarry