dotnetman Posted June 10, 2005 Posted June 10, 2005 Friends, I am trying to come up with a custom position control (trackbar you can say :D). I have a background horizontal bar (picturebox) over which I have the slider(another picturebox). Essentially, the slider should move based on where the user clicks on the background bar. For that, I need to somehow find the coordinates where the user clicked on the back image. I tried the cursor object. However, it gives co-ordinates relative to the container control's dimensions. I would want it to be relative to the user control's dimensions, coz based on those (static) values, I need to move the slider. Any ideas how this can be done? Do let me know. DNM Quote
Machaira Posted June 10, 2005 Posted June 10, 2005 Use the MouseDown or MouseUp events. The "e" param contains the point on which the user clicked. Quote Here's what I'm up to.
dotnetman Posted June 10, 2005 Author Posted June 10, 2005 The MouseEventArgs (in MouseDown) work perfect. I am able to move the slider left n right. However, how do I simulate dragging? When the slider is held and dragged, it should move on the horizontal path. But how?? Quote
Machaira Posted June 10, 2005 Posted June 10, 2005 Try: Private _mouseDown As Boolean Private _oldX As Integer Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown _mouseDown = True _oldX = e.X End Sub Private Sub PictureBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseUp _mouseDown = False End Sub Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove If _mouseDown Then PictureBox2.Left = e.X - (_oldX - PictureBox2.Left) End If End Sub Quote Here's what I'm up to.
dotnetman Posted June 10, 2005 Author Posted June 10, 2005 Works like a charm. Thanx a lot Machaira. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.