在按住按钮控件的同时写一个Sub重复

时间:2013-06-16 20:39:35

标签: vb.net winforms visual-studio-2010

我的应用程序中有一个表单,允许用户通过单击每个数字(小时,分钟,秒)的向上或向下按钮或使用键盘直接输入数字来输入时间。以下是对表单的捕获:

enter image description here

我正在尝试编写附加到MouseDown事件的事件处理程序,该事件处理程序将延迟两秒,然后开始向上或向下递增数字(取决于按下的按钮),直到释放按钮。

如果我没有提供足够的信息,请告诉我,我会尽力详细说明。

2 个答案:

答案 0 :(得分:2)

如果您使用的是WPF,则可以使用RepeatButton代替Button

来自MSDN的

样本:

<RepeatButton Width="100" DockPanel.Dock="Top" 
              Delay="500" Interval="100" 
              Click="Increase">
  Increase
</RepeatButton>

Private Sub Increase(ByVal sender As Object, ByVal e As RoutedEventArgs)    
    Num = CInt(valueText.Text)    
    valueText.Text = ((Num + 1).ToString())
End Sub

对于WinForms,this tutorial from CodeProject包含您需要知道的所有内容。

答案 1 :(得分:-1)

你想要实现的内容已经内置在DateTimePicker中,只需更改一些属性,用户点击时间部分就可以在使用updown按钮之前滚动:

    Me.DateTimePicker1.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.DateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Time
    Me.DateTimePicker1.ShowUpDown = True
相关问题