Hello all.
I am making a virtual iPod touch in VB.NET, and I hate it how I have a form that I can't drag and move the form around the screen, I've trying making the form goto Mouse's location when the mouse moves and Dragging = True, but that doesn't work and makes the form flicker around at the speed of light. :(
Thanks, can anyone help me please? :)

mitchfizz05.

Recommended Answers

All 2 Replies

In order to avoid the flickering, use the SetStyle method of the form.

    Public Sub EnableDoubleBuffering()
       ' Set the value of the double-buffering style bits to true.
       Me.SetStyle(ControlStyles.DoubleBuffer _
         Or ControlStyles.UserPaint _
         Or ControlStyles.AllPaintingInWmPaint, _
         True)
       Me.UpdateStyles()
    End Sub

Place this code in the Form's mouse down event.

'On mousedown'
If e.Button = Windows.Forms.MouseButton.Left Then

Capture = True
relocateTimer.Start()

End If

Place this in the mouse up event.

'On mouseup'
relocateTimer.Stop
Capture = False

Next place this in the timer's tick event.

'Place this code in a timer.'
'Set tic to 15 milliseconds.'

dim i as integer = 0

i+= 1

If i > 15 Then
Me.location = new Point (MousePosition.x - (me.width /2 ),Mouseposition.y - (me.height /2))
End If

Now, after the user holds the mouse for 15 milliseconds, it will start to relocate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.