Slider UserControl

Allen G
12-09-2004, 01: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

Iceplug
12-09-2004, 08:34 PM
You cannot do it on the picSlider control because the picSlider control is moving. In order to do a slider with this, you have to draw the slider yourself.
The MouseMove event fires also when a control moves. :)

Allen G
12-10-2004, 02:59 AM
You cannot do it on the picSlider control because the picSlider control is moving. In order to do a slider with this, you have to draw the slider yourself.
The MouseMove event fires also when a control moves. :)

Well, has it changed from VB6 from .NET. Because, I've seen source code to VB6 sliders that do the same thing as mine, and they just use the UserControl for all the mouse events. I try to do this with .NET and it doesn't work at all.

Can you give me any tips on how to draw the Slider Image?

Iceplug
12-10-2004, 08:57 AM
Your usercontrol should have a paint event. That is where you draw your slider.
You should have the value of the slider stored somewhere. From there, you should be able to calculate where you want the image to appear. :)

Allen G
12-10-2004, 11:24 AM
Your usercontrol should have a paint event. That is where you draw your slider.
You should have the value of the slider stored somewhere. From there, you should be able to calculate where you want the image to appear. :)

I got it done, now to just calculate the values. Thanks for your help!
:D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum