Results 1 to 5 of 5

Thread: How do I move (by dragging) a form with no title bar?

  1. #1

    Thread Starter
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    How do I do this?

  2. #2
    Guest
    In the dclaration section of your form:
    Code:
    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
    Private Declare Sub ReleaseCapture Lib "user32" ()
    
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    And in the form:
    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
       If Button = 1 Then
          ReleaseCapture
          SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
       End If
    End Sub
    That's all.

  3. #3
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    make a module (bas)

    put this in the general declarations of the module:

    Code:
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
    Declare Function ReleaseCapture Lib "user32" () As Long
    Public Const WM_NCLBUTTONDOWN = &HA1
    Public Const HTCAPTION = 2
    then under that but not in the general declarations put:

    Code:
    Public Sub MoveForm(frm As Form)
    ReleaseCapture
    X = SendMessage(frm.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& )
    now you need a label in the form ... in the label's mousedown event type:

    Code:
    MoveForm Me
    ----------------
    i did not write this code - it does work but the credit doesn't belong to me ....

    [Edited by theman32x on 08-26-2000 at 07:24 PM]

  4. #4
    Guest
    Here's how to do it without using API:

    Code:
    Dim oldX As Long, oldY As Long, isMoving As Boolean
    '^goes in form declarations
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    oldX = X
    oldY = Y
    isMoving = True
    End Sub
    
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If isMoving Then
        Me.Top = Me.Top - (oldY - Y)
        Me.Left = Me.Left - (oldX - X)
    End If
    End Sub
    
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    isMoving = False
    End Sub

  5. #5
    Guest
    Try this:
    Code:
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    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
    Const WM_SYSCOMMAND = &H112
    Const SC_MOVE_EX = &HF012
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE_EX, 0
        End If
    End Sub

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