Results 1 to 3 of 3

Thread: Move a form with no border

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Move a form with no border

    Works for anything else you specify, like say a tab control, pic box etc.

    VB Code:
    1. Private OldX As Integer
    2. Private OldY As Integer
    3. Private DragMode As Boolean
    4. Dim MoveMe As Boolean
    5.  
    6. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    7.  
    8.     MoveMe = True
    9.     OldX = X
    10.     OldY = Y
    11.  
    12. End Sub
    13.  
    14. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    15.  
    16.     If MoveMe = True Then
    17.         Me.Left = Me.Left + (X - OldX)
    18.         Me.Top = Me.Top + (Y - OldY)
    19.     End If
    20.  
    21. End Sub
    22.  
    23. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    24.  
    25.     Me.Left = Me.Left + (X - OldX)
    26.     Me.Top = Me.Top + (Y - OldY)
    27.     MoveMe = False
    28.  
    29. End Sub

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    There is an API way. I'll look for it...


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Here it is :

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ReleaseCapture Lib "user32" () As Long
    4. 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
    5.  
    6. Const WM_NCLBUTTONDOWN As Long = &HA1
    7. Const HTCAPTION As Long = 2
    8.  
    9. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    10.    Dim lngReturnValue As Long
    11.    If Button = vbLeftButton Then
    12.        Call ReleaseCapture
    13.        lngReturnValue = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    14.    End If
    15. End Sub


    Has someone helped you? Then you can Rate their helpful post.

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