PC Review


Reply
Thread Tools Rate Thread

Drag label position on userform at runtime - jerky movement

 
 
hooksie2@hotmail.com
Guest
Posts: n/a
 
      6th Dec 2006
I want to be able to drag a label (or other suitable control to act
like a box) on a userform at runtime.

I have written the following to do this but have these problems:
1) the movement is quite jerky - at times the label can even jump
backwards although I am only moving the mouse fowards
2) the mouse gets ahead of the label

Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Static sngXOld As Single
Dim sngDelta As Single

If m_blnMouseIsDown Then
sngDelta = (X - sngXOld)
Me.Label1.Left = Me.Label1.Left + sngDelta
Me.Label2.Left = Me.Label2.Left + sngDelta
DoEvents
sngXOld = X
End If
End Sub

I can improve things a little bit by only moving the label once the
mouse is moved a certain minimum distance, ie. If Abs(sngDelta) > 5,
but it's still not perfect and the mouse still gets ahead of the label.

Can anyone suggest an alternative approach - or have I simply
overlooked something here?

Thanks a lot,
Andrew

 
Reply With Quote
 
 
 
 
hooksie2@hotmail.com
Guest
Posts: n/a
 
      6th Dec 2006
Solved it.

I am measuring the cursor position relative to the label position - but
at the same time I am moving the label so if the mouse movement slows
down (for a fraction of a second) the cursor position relative to the
label can move in the opposite direction - it is this that causes the
flicker.

To overcome this I am now using the GetCursorPos API (together with
conversion from pixels to point count) and use that to track the
relative mouse movement. Works perfectly

Best regards,
Andrew


(E-Mail Removed) wrote:
> I want to be able to drag a label (or other suitable control to act
> like a box) on a userform at runtime.
>
> I have written the following to do this but have these problems:
> 1) the movement is quite jerky - at times the label can even jump
> backwards although I am only moving the mouse fowards
> 2) the mouse gets ahead of the label
>
> Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As
> Integer, ByVal X As Single, ByVal Y As Single)
> Static sngXOld As Single
> Dim sngDelta As Single
>
> If m_blnMouseIsDown Then
> sngDelta = (X - sngXOld)
> Me.Label1.Left = Me.Label1.Left + sngDelta
> Me.Label2.Left = Me.Label2.Left + sngDelta
> DoEvents
> sngXOld = X
> End If
> End Sub
>
> I can improve things a little bit by only moving the label once the
> mouse is moved a certain minimum distance, ie. If Abs(sngDelta) > 5,
> but it's still not perfect and the mouse still gets ahead of the label.
>
> Can anyone suggest an alternative approach - or have I simply
> overlooked something here?
>
> Thanks a lot,
> Andrew


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
jerky mouse and video movement idruminasteria Windows Vista Performance 0 11th May 2008 08:26 PM
drag & drop shapes, label and fields to design report at runtime Jean Christophe Avard Microsoft VB .NET 1 1st Aug 2005 04:01 PM
Jerky Movement When Selecting a Favorite Fred 2002 Windows XP General 4 15th Nov 2003 10:04 PM
XP mouse delays, jerky delayed movement Steve Hall Windows XP Performance 0 12th Nov 2003 09:48 PM
When scrolling web pages the movement is jerky, not smooth. Bucky Windows XP Internet Explorer 1 13th Sep 2003 01:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:04 PM.