我目前使用这段代码来修复一个错误,即如果您单击水平TrackBar上的某处,它会跳到TrackBar的中间,然后跳到末尾。所以这段代码修复了这个bug,它现在跳转到您单击的位置。
但仍然存在一个问题,当我保持我的鼠标按下,并在TrackBar周围移动滑块应该跟随,但它只是重置到开始位置,我如何让它跟随在光标的顶部?我需要一个定时器控件吗?
Private Sub tbTest_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbTest.MouseDown
Dim dblValue As Double
'Jump to the clicked location, bug FIX.
dblValue = (Convert.ToDouble(e.X) / Convert.ToDouble(tbTest.Width)) * (tbTest.Maximum - tbTest.Minimum)
tbTest.Value = Convert.ToInt32(dblValue)
End Sub发布于 2013-07-02 05:51:44
使该方法处理MouseDown()和MouseMove()事件,如下所示:
Private Sub tbTest_MovePointer(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tbTest.MouseDown, tbTest.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim dblValue As Double
'Jump to the clicked location, bug FIX.
dblValue = (Convert.ToDouble(e.X) / Convert.ToDouble(tbTest.Width)) * (tbTest.Maximum - tbTest.Minimum)
tbTest.Value = Convert.ToInt32(dblValue)
End If
End Sub*请注意在第一行末尾的Handles关键字之后列出的多个事件。我还添加了一个检查,以确保鼠标左键已按下。
https://stackoverflow.com/questions/17414108
复制相似问题