我的表单中有两个 DateTimePicker 对象,
“hh : mm tt”的自定义格式
ShowUpDown = 真
前任。
Time : 12:00
当我按向上键时,我想将分钟值增加到 +30
Time : 12:30 PM
我的表单中有两个 DateTimePicker 对象,
“hh : mm tt”的自定义格式
ShowUpDown = 真
前任。
Time : 12:00
当我按向上键时,我想将分钟值增加到 +30
Time : 12:30 PM
使用事件
DataTimePicket.KeyDown
样品用法:
VB.NET
Private Sub Form1_Load(sender As Object, e As EventArgs)
dateTimePicker1.KeyDown += DateTimePicker1OnKeyUp
End Sub
Private Sub DateTimePicker1OnKeyUp(sender As Object, e As KeyEventArgs)
If e.KeyValue = 38 Then
' up
dateTimePicker1.Value = dateTimePicker1.Value.AddSeconds(30)
e.SuppressKeyPress = True
ElseIf e.KeyValue = 40 Then
'down
dateTimePicker1.Value = dateTimePicker1.Value.AddSeconds(-30)
e.SuppressKeyPress = True
End If
End Sub
C#
private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.KeyDown += DateTimePicker1OnKeyUp;
}
private void DateTimePicker1OnKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyValue == 38) // up
{
dateTimePicker1.Value = dateTimePicker1.Value.AddSeconds(30);
e.SuppressKeyPress = true;
}
else if (e.KeyValue == 40) //down
{
dateTimePicker1.Value = dateTimePicker1.Value.AddSeconds(-30);
e.SuppressKeyPress = true;
}
}