Results 1 to 1 of 1

Thread: How to use the drag 'n' drop.

  1. #1

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    How to use the drag 'n' drop.

    I attached them all at the buttom

    This is how to make a button, Command1, move on the form, form1, freally:
    You need Command1 and Form1
    VB Code:
    1. Dim StartX, StartY
    2. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    3.         StartX = X 'Store button starting location
    4.         StartY = Y 'Store button starting location
    5.         Command1.Drag vbBeginDrag 'Starts drag
    6. End Sub
    7.    
    8. Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.         Command1.Drag vbEndDrag 'Ends Drag mode
    10.        
    11. End Sub
    12.    
    13. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    14.     Source.Move X - StartX, Y - StartY 'Move the control to droped location
    15. End Sub


    This is how to make that if the button has been droped on the label, Label1, it will reposion itself on it, mostly used on games that want you to limit that place a control can be droped on.

    You need Command1 and Label1, make sure you have the label one in a diffrent color so you can see it:

    VB Code:
    1. Dim StartX, StartY
    2. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    3.         StartX = X 'Store button starting location
    4.         StartY = Y 'Store button starting location
    5.         Command1.Drag vbBeginDrag 'Starts drag
    6. End Sub
    7.    
    8. Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.         Command1.Drag vbEndDrag 'Ends Drag mode
    10. End Sub
    11.    
    12. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    13.     Source.Move X - StartX, Y - StartY 'Move the control to droped location
    14. End Sub
    15.  
    16.  
    17. Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
    18.     Source.Move Label1.Left, Label1.Top 'Move the control to droped location
    19. End Sub

    This is how to change the control veriable according to where to posion it on:

    You need a Command1, Label1, and Label2. Change label1 background to blue and label2 to red.

    VB Code:
    1. Dim StartX, StartY
    2. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    3.     StartX = X 'Store button starting location
    4.     StartY = Y 'Store button starting location
    5.     Command1.Drag vbBeginDrag 'Starts drag
    6. End Sub
    7.    
    8. Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.         Command1.Drag vbEndDrag 'Ends Drag mode
    10. End Sub
    11.    
    12. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    13.     Source.Move X - StartX, Y - StartY 'Move the control to droped location
    14.     Source.BackColor = Me.BackColor
    15. End Sub
    16. Private Sub Label1_DragDrop(Source As Control, X As Single, Y As Single)
    17.     Source.Move Label1.Left, Label1.Top 'reposion the control posion to the label
    18.     Source.BackColor = Label1.BackColor ' Change the control background
    19. End Sub
    20.  
    21. Private Sub Label2_DragDrop(Source As Control, X As Single, Y As Single)
    22.     Source.Move Label2.Left, Label2.Top 'reposion the control posion to the label
    23.     Source.BackColor = Label2.BackColor ' Change the control background
    24. End Sub
    Attached Files Attached Files
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width