Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Drag label position on userform at runtime - jerky movement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hooksie2@hotmail.com - 06 Dec 2006 01:04 GMT
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
hooksie2@hotmail.com - 06 Dec 2006 14:43 GMT
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

> I want to be able to drag a label (or other suitable control to act
> like a box) on a userform at runtime.
[quoted text clipped - 27 lines]
> Thanks a lot,
> Andrew
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.