Allen G
12-09-2004, 12:38 PM
I'm having problems creating a Slider. Everything is grand except for the part where the dragging comes into play. It seems that when I try to use the MouseMove event the thing just flips out completely, it will start grabbing more than 1 X coordinate, even when the mouse isn't moving.
picSlider is a Picture Box.
Example:
38
32
38
32
38
32
38
32
38
32
38
Would be Outputted repeatedly, again, while the mouse isn't even moving. The following code is used to produce the above values.
Private Sub picSlider_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSlider.MouseMove
If e.Button = MouseButtons.Left Then
Call SetPosition(e.X)
Debug.WriteLine(e.X)
End If
End Sub
This behavior only happens while using the picture boxes MouseMove event. The following works perfectly, If I were to drag on the UserControl itself.
Private Sub Slider_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Call SetPosition(e.X)
Debug.WriteLine(e.X)
End If
End Sub
Private Sub SetPosition(ByVal X As Integer)
If X > Me.Width - picSlider.Width Then
X = Me.Width - picSlider.Width
End If
If X < 0 Then
X = 0
End If
picSlider.Left = X
End Sub
I really need it to work when I click and drag on the picSlider picture box. Can anyone help?
Thanks,
-Allen
picSlider is a Picture Box.
Example:
38
32
38
32
38
32
38
32
38
32
38
Would be Outputted repeatedly, again, while the mouse isn't even moving. The following code is used to produce the above values.
Private Sub picSlider_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSlider.MouseMove
If e.Button = MouseButtons.Left Then
Call SetPosition(e.X)
Debug.WriteLine(e.X)
End If
End Sub
This behavior only happens while using the picture boxes MouseMove event. The following works perfectly, If I were to drag on the UserControl itself.
Private Sub Slider_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Call SetPosition(e.X)
Debug.WriteLine(e.X)
End If
End Sub
Private Sub SetPosition(ByVal X As Integer)
If X > Me.Width - picSlider.Width Then
X = Me.Width - picSlider.Width
End If
If X < 0 Then
X = 0
End If
picSlider.Left = X
End Sub
I really need it to work when I click and drag on the picSlider picture box. Can anyone help?
Thanks,
-Allen