0

フォームに 2 つの DateTimePicker オブジェクトがあり、

"hh : mm tt" のカスタム形式

ShowUpDown = True

元。

Time : 12:00

アップキーを押したとき、分値を+30に増やしたい

Time : 12:30 PM
4

1 に答える 1

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;
        }
    }
于 2013-01-14T15:20:26.560 に答える