Link to home
Start Free TrialLog in
Avatar of LosBear
LosBear

asked on

drag window using image

how do I drag a window (form) by clicking and dragging on an image?
I have set the borderstyle to none and mimic'd topbar with an image, but now I can't drag (obviously).  How do i make the image (looks just like a normal titlebar with the X on it) drag the entire window?
thx in advance!
Bear
Avatar of DeAn
DeAn

assumes a picturebox name Picture1

Option Explicit

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

Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Const WM_SYSCOMMAND = &H112
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ReleaseCapture
    SendMessage hwnd, WM_NCLBUTTONDOWN, _
        HTCAPTION, 0&

    ' Or use:
'    SendMessage hwnd, WM_SYSCOMMAND, _
'        &HF012&, 0&
End Sub

ASKER CERTIFIED SOLUTION
Avatar of DeAn
DeAn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LosBear

ASKER

so image wont' work?
Avatar of LosBear

ASKER

Well done; it worked like a charm.  I set the picture box properties to flat, no border, etc. and it works!
Thanks dude