Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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
0
LosBear
Asked:
LosBear
  • 2
  • 2
1 Solution
 
DeAnCommented:
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

0
 
DeAnCommented:
you should use a PictureBox instead of Image for that code to work.
0
 
LosBearAuthor Commented:
so image wont' work?
0
 
LosBearAuthor Commented:
Well done; it worked like a charm.  I set the picture box properties to flat, no border, etc. and it works!
Thanks dude
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now