Results 1 to 7 of 7

Thread: Moving Command Buttons

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Moving Command Buttons

    Hi,

    Is there a way to allow the user to move a command button around in a picture box for example. (or a form)?

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    how about setting a right click popup menu to the button..then if they pick "move" from the menu... allow then to click another spot on the form..and set the top / left


    or check for a special keycombo... like if they hold SHIFT and click and hold the button...allow a drag/drop.

    but..in a nutshell, YES you can let the user move the button
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    spetnik
    Guest
    Sure, but be specific about what you want. Do u want the user to b able to drag it? Do you want it to move automatically?

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking The Girraffes are coming...run for your haggises

    Like this you mean:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim intLeftGap          As Integer
    4. Dim intTopGap           As Integer
    5.  
    6. Private Sub Command1_Click()
    7.     Load Form2
    8.     Form2.Show vbModal, Me
    9. End Sub
    10.  
    11. Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    12.     If Button = vbRightButton Then
    13.         intLeftGap = X
    14.         intTopGap = Y
    15.     End If
    16. End Sub
    17.  
    18. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    19.     If Button = vbRightButton Then
    20.         Command1.Left = X + Command1.Left - intLeftGap
    21.         Command1.Top = Y + Command1.Top - intTopGap
    22.     End If
    23. End Sub

  5. #5

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Thanks WokaWidget, that's exactly what I needed. I don't care about the Click event because the user will be only allowed to move the buttons around a picture box.

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    ok here...

    change the Drag mode of the command button to automatic


    then in the Dragdrop event of the form.

    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Left = X
    Source.Top = Y
    End Sub




    thats it
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    thanks geoff_xrx. However, the button will be placed according to the mouse_cursors's x and y properties as oppose to the buttons.

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