Я добавил DateTimePicker в мою C# форму. Я использую формат Time
с ShowUpDown = true
. Когда я использую кнопки вверх / вниз, часы, минуты или секунды увеличиваются / уменьшаются. Когда переполняются секунды (с 59 до 0 или от 0 до 59, я бы хотел увеличить минуты. Есть ли способ сделать это?
как это работает сейчас:
- TimerPicker = 00:01:59 → нажмите UpKey на секунду → TimerPicker = 00:01:00
- TimerPicker = 05:00:38 → нажмите DownKey на минуту → TimerPicker = 05: 59: 38
как мне бы хотелось, чтобы это работало:
- TimerPicker = 00:01:59 → нажмите клавишу UpKey на секунду → TimerPicker = 00: 02: 00
- TimerPicker = 05 : 00: 38 → нажмите DownKey на минуту → TimerPicker = 04: 59: 38
Редактировать: Вот мой код, связанный с DateTimePicker:
DataGraph.Designer.cs:
this.TimePerDivisionPicker = new System.Windows.Forms.DateTimePicker();
//
// TimePerDivisionPicker
//
this.TimePerDivisionPicker.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.TimePerDivisionPicker.CustomFormat = "";
this.TimePerDivisionPicker.Format = System.Windows.Forms.DateTimePickerFormat.Time;
this.TimePerDivisionPicker.ImeMode = System.Windows.Forms.ImeMode.On;
this.TimePerDivisionPicker.Location = new System.Drawing.Point(83, 16);
this.TimePerDivisionPicker.Name = "TimePerDivisionPicker";
this.TimePerDivisionPicker.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.TimePerDivisionPicker.ShowUpDown = true;
this.TimePerDivisionPicker.Size = new System.Drawing.Size(85, 20);
this.TimePerDivisionPicker.TabIndex = 4;
this.TimePerDivisionPicker.Value = new System.DateTime(2020, 3, 2, 0, 1, 0, 0);
this.TimePerDivisionPicker.ValueChanged += new System.EventHandler(this.TimePerDivisionPicker_ValueChanged);
DataGraph.cs:
private void TimePerDivisionPicker_ValueChanged(object sender, EventArgs e)
{
String[] temp = TimePerDivisionPicker.Text.Split(':');
UInt16 tempHours = Convert.ToUInt16(temp[0]);
UInt16 tempMinutes = Convert.ToUInt16(temp[1]);
UInt16 tempSecondes = Convert.ToUInt16(temp[2]);
TimePerDivision = Convert.ToUInt32(tempHours * 3600 + tempMinutes * 60 + tempSecondes);
}