Private Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () 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 LongPrivate Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Long
If Button = 1 Then
ReleaseCapture
i = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub

解决方案 »

  1.   

    Const HTCAPTION = 2
    Const WM_NCLBUTTONDOWN = &HA1
    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 Long) As Long
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim r As Long
        Dim i
        If Button = 1 Then
            i = ReleaseCapture()
            r = SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
        End If
    End Sub
      

  2.   

    除了api函数,没有其他方法了吗?
      

  3.   


    Dim Curx As Single, Cury As SinglePrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Curx = X
        Cury = Y
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then
            Me.Top = Me.Top + Y - Cury
            Me.Left = Me.Left + X - Curx
            Curx = X
            Cury = Y
        End If
    End Sub
      

  4.   

    API代码少功能又足,我一直用它。
      

  5.   

    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" ()
    Const WM_NCLBUTTONDOWN = &HA1
    Const HTCAPTION = 2
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim lngReturnValue As Long
        If Button = 1 Then
            'Release capture
            Call ReleaseCapture
            'Send a 'left mouse button down on caption'-message to our form
            lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
        End If
    End Sub
    Private Sub Form_Paint()
        Me.Print "Click on the form, hold the mouse button and drag it"
    End Sub