Identifying Coordinates on Click

dotnetman

Newcomer
Joined
Jan 4, 2005
Messages
19
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
 
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??
 
Try:
Code:
    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
 
Back
Top