Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


moving a form


moving a form

Author
Message
kwandobe
kwandobe
Forum God
Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)

Group: Forum Members
Posts: 22, Visits: 4

I am trying to allow a user to drag a form by clicking and holding a picturebox. The form does not have a border. Heres the code I am trying to use.

 

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long                              

Public Declare Function ReleaseCapture Lib "user32" () As Long

 
 

Public Const WM_SYSCOMMAND = &H112 Public Const WM_MOVE = &HF012

 
 
Public Sub FormDrag(TheForm As Form)
    Call ReleaseCapture
    Call SendMessage(TheForm.hWnd, WM_SYSCOMMAND, WM_MOVE, 0)
End Sub


-kwandobe


Mark
Mark
Forum God
Forum God (144K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

Here is a code snippet that I use for removing the titlebar of a form and then allow it to be move. Use a regular sizeable form.

Option Explicit

'API Calls Used To Remove The Title Bar From Window (Make A Sizeable Borderless Form)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
                            (ByVal hwnd As LongByVal nIndex As Long, _
                            ByVal dwNewLong As LongAs Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
                            (ByVal hwnd As LongByVal nIndex As LongAs Long
                            
Private Const GWL_STYLE = (-16)
Private Const WS_DLGFRAME = &H400000

'API Calls Used To Move A Form With The Mouse
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                            (ByVal hwnd As LongByVal wMsg As Long, _
                            ByVal wParam As Long, lParam As Any) As Long

Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Sub Form_Load()
    'ERASE the Title Bar
    SetWindowLong Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) + WS_DLGFRAME
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Move the form with the Left Mouse Button
    If Button = vbLeftButton Then
        Me.MousePointer = vbSizeAll
        Call ReleaseCapture
        Call SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
        Me.MousePointer = vbArrow
    End If
End Sub

Private Sub Command1_Click()
    Unload Me
End Sub

kwandobe
kwandobe
Forum God
Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)Forum God (5.9K reputation)

Group: Forum Members
Posts: 22, Visits: 4
Works like a charm man, Thanks!

-kwandobe


GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search