我的表单中有两个DateTimePicker对象,
“hh:mm tt”的自定义格式
ShowUpDown = True
离。
Time : 12:00
当我按向上键时,我想将分钟值增加到+30
Time : 12:30 PM
答案 0 :(得分:0)
使用活动
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;
}
}