Results 1 to 18 of 18

Thread: Moving a command

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Moving a command

    Hi to all:

    I need to let the user move a command1 in a form!

    How can I do This?

    Thanks

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Moving a command

    Quote Originally Posted by sacramento
    Hi to all:

    I need to let the user move a command1 in a form!

    How can I do This?

    Thanks

    Try This Post
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Moving a command

    Try something like this:

    VB Code:
    1. Dim intxx As Integer
    2. Dim intyy As Integer
    3.  
    4. Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    5.     If Button = vbLeftButton Then
    6.         intxx = X
    7.         intyy = Y
    8.         cmdButton.MousePointer = vbSizeAll
    9.     End If
    10. End Sub
    11.  
    12. Private Sub cmdButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    13.     If Button = vbLeftButton Then
    14.         cmdButton.Left = (cmdButton.Left - intxx) + X
    15.         cmdButton.Top = (cmdButton.Top - intyy) + Y
    16.     End If
    17. End Sub
    18.  
    19. Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    20.     cmdButton.MousePointer = vbDefault
    21. End Sub

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    Thanks for the thread:

    This is the code:

    VB Code:
    1. Option Explicit
    2.  
    3. Private mbDragging As Boolean
    4. Private nX As Single, nY As Single
    5.  
    6. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    7.   Text1.Move X - nX, Y - nY
    8.   mbDragging = False
    9. End Sub
    10.  
    11. Private Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    12.   If Not mbDragging Then
    13.     nX = X
    14.     nY = Y
    15.     mbDragging = True
    16.   End If
    17. End Sub

    In fact works very well,but I want fixed the object moved to the position I had left him.
    Any suggestions?

    Thanks

  5. #5
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Moving a command

    For something different, try this:

    Create a new project, add a command button on to it and add this code to the form:

    VB Code:
    1. Option Explicit
    2.  
    3. Const WM_NCLBUTTONDOWN = &HA1
    4. Private Const HTCAPTION = 2
    5.  
    6. Private Declare Function ReleaseCapture Lib "user32" () As Long
    7.  
    8. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    9.  
    10. Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11.     ReleaseCapture
    12.     SendMessage Command1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
    13. End Sub

    Does this do what you want?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    Hi Blade:

    Yes that's what I want and work very well,but I stay with the same problem.The command1 don't fix the position where I had move it!

    Do you have any suggestion to do this?

    Thanks

  7. #7
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Moving a command

    Not sure I understand you.

    If I move the command button with the code I posted, it stays wherever I put it? Are you calling some other code that resets it position?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    yes that correct the object stays wherever I put it,but if you leave the form and enter again the object is in the original position you had put it in the form!
    Do you mean what I say?

    Thanks

  9. #9
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Moving a command

    Quote Originally Posted by sacramento
    yes that correct the object stays wherever I put it,but if you leave the form and enter again the object is in the original position you had put it in the form!
    Do you mean what I say?

    Thanks

    Oh, you want to make it there perminamt perminant....

    The only way I can think to do this is to store the information in a file and then use that to load the control in the correct place when the form is loaded.

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  10. #10
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Moving a command

    right. Yep, as Ryan say, you'll need to store it's location in a file (or registry/database) and then get this info everytime you load the form up.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    ok I see...something like this?


    data1.recordset![position]=command1.top
    data1.recordset![position1]=command1.left

  12. #12
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Moving a command

    Quote Originally Posted by sacramento
    ok I see...something like this?


    data1.recordset![position]=command1.top
    data1.recordset![position1]=command1.left
    Exactly

    Maybe the registry would be better in this case because is is only two values...?

    RyanJ
    My Blog.

    Ryan Jones.

  13. #13
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Moving a command

    try this

    VB Code:
    1. Option Explicit
    2. Dim intxx As Integer
    3. Dim intyy As Integer
    4.  
    5. Private Sub cmdButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6.     If Button = vbLeftButton Then
    7.         intxx = X
    8.         intyy = Y
    9.         Cmdbutton.MousePointer = vbSizeAll
    10.     End If
    11. End Sub
    12.  
    13. Private Sub cmdButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    14.     If Button = vbLeftButton Then
    15.         Cmdbutton.Left = (Cmdbutton.Left - intxx) + X
    16.         Cmdbutton.Top = (Cmdbutton.Top - intyy) + Y
    17.     End If
    18. End Sub
    19.  
    20. Private Sub cmdButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    21.     Cmdbutton.MousePointer = vbDefault
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. If len(Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 then
    26.     Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)
    27.     Cmdbutton.Top = GetSetting(App.EXEName, "settings", "Y", Cmdbutton.Top)
    28. end if
    29. End Sub
    30.  
    31. Private Sub Form_Unload(Cancel As Integer)
    32.     SaveSetting App.EXEName, "settings", "X", Cmdbutton.Left
    33.     SaveSetting App.EXEName, "settings", "Y", Cmdbutton.Top
    34. End Sub

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    I have problems with this line...I don't now why...the object is there!!!

    run time error '424'
    object required

    Code:
    If len(Cmdbutton.Left = GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 then

  15. #15
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Moving a command

    Try changing it too:

    VB Code:
    1. If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Moving a command

    something strange...now the error is

    variable not define

    Code:
    If Len(GetSetting(App.EXEName, "settings", "X", Cmdbutton.Left)) > 0 Then

  17. #17
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Moving a command

    woops my bad..shows what copying and pasting gets you ;?

  18. #18
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Moving a command

    you have a command button named cmdbutton...right?

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