Question Using shapes to create a custom track bar for media player

Retrophobe

Member
Joined
Feb 27, 2009
Messages
6
Location
London, England
Programming Experience
3-5
Hi all,

I've been hammering away at this code all day and i've finally submitted to defeat and realise I wont complete it without the aid of the helpful folk on vb.net forums.
I am using a line shape and custom picture box to simulate a track bar for a media player I am creating. The custom picture box is programmed to follow the mouse on the mouseMove event. The problem is that whenever the picture box is at either end of the line it stops responding to the mouse. Here's the code

VB.NET:
 Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
        MyBase.OnMouseMove(e)

        If e.Button = Windows.Forms.MouseButtons.Left Then
            If Me.Left > 120 And Me.Right < 340 Then
                Dim diffX As Integer = e.X - Me.origX
                Select Case Me.dragAction
                    Case Area.Center
                        Dim loc As Point = Me.Location
                        loc.Offset(diffX, 0)
                        Me.Location = loc
                End Select
            ElseIf Me.Left <= 120 Then
                Dim loc As Point = Me.Location
                loc.Offset(0, 0)
                Me.Location = loc
            ElseIf Me.Right >= 340 Then
                Dim loc As Point = Me.Location
                loc.Offset(0, 0)
                Me.Location = loc
            End If
        End If

    End Sub

So basically what I need to know is how can I keep the picture box within a certain range(i.e. 121 -339 pixels on x-axis) and prevent movement if the mouse is outside of this range.

Thanks In advance :)
 
Last edited:
Back
Top