We help IT Professionals succeed at work.

drag and drop question

heydude
heydude asked
on
Medium Priority
239 Views
Last Modified: 2010-04-07
I am using vb 6 and I want to be able to drag and drop controls on a form at runtime(for this example a textbox or a label) I have an image of a ruler on the top and side of the form and when I drag the textbox, etc... to a spot on the ruler it always snaps back a few and never lines up correctly. I tried a couple of examples I found on this site and it didn't work. Can someone post a simple example of how to do this? I want the control to stay at the point it is dropped not move.

Thank you,

Matt
Comment
Watch Question

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
Assuming your Label (Label1) is a Control Array:

Option Explicit

Private startX As Single
Private startY As Single

Private Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        startX = X
        startY = Y
    End If
End Sub

Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Label1(Index).Move Label1(Index).Left + (X - startX), Label1(Index).Top + (Y - startY)
    End If
End Sub

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.