[Webinar] Streamline your web hosting managementRegister Today

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

Drag a form with mousepointer?

I've turned the ordinary titlebar off in my app (borderstyle = None) and I've made my own more graphical layout. Now I want to make it possible for the user to click my own titlebar and drag the whole form just like they could before. I'm having problem with the mousemove event. I know there is very little code to solve this but my brain doesn't function right now! The control to use for the bar could be a picture, Image or some control that can be invisible (background sees through) but still work.
0
raya70
Asked:
raya70
  • 6
  • 4
  • 2
  • +1
1 Solution
 
JuiletteCommented:
'Add the following code to the declarations section of a form

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


'Add this code to the form's MouseMove procedure:
'
      Dim lngReturnValue As Long
         If Button = 1 Then
            Call ReleaseCapture
            lngReturnValue = SendMessage(Form1.hWnd,             WM_NCLBUTTONDOWN, _
            HTCAPTION, 0&)
      End If

0
 
raya70Author Commented:
Uhmm, nothing happens. What exactly should I do to use it?
0
 
VBGuruCommented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
JuiletteCommented:
true...it only works on the form if you look at the code...ie...write your title bar on the form and not on another control.
0
 
JuiletteCommented:
it works anywhere on the form so if your form is colored one color you can direct the user to click anywhere on the blue for example to move the form.

0
 
raya70Author Commented:
VBGuru: Thanx, but that was basicaly what Juilette proposed.

Juilette: It doesn't move at all. I'm I missing something here?
0
 
JuiletteCommented:
Raya70: As for the proposed answer by  vbGuru:
that tip is exactly the same code as I posted above...nothing new there. you can't move unless you click on the form...my answer is as correct as it gets.

Wayne
0
 
raya70Author Commented:
Sorry again, but the form _won't_ move and (ofcourse) I use the mousebutton; single click and/or pressed doesn't work; neither left or right.
Is there some other property that has to be set for the form to make it work?

I'm using some ohter API's too (to look for mousecoord's and one for Bitblitting). Does that interfeer?
0
 
JuiletteCommented:
it could but shouldn't
....I just tried the code and it works as long as I'm in the form and not on any other control.
Did you coy and paste the code to avoid errors?
Make sure the second part is in the mouse move on top of other code if you have any in there.
Wayne
0
 
mcriderCommented:
Put a picturebox on the form called "Picture1" then add the following code to the DECLARATIONS SECTION of the form.

You can put the picture box a the top of the form and size it as if it were a title bar...  Color it if you want...

'--------------------------------------------------
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 Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim lngReturnValue As Long
   If Button = 1 Then
      Call ReleaseCapture
      lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
   End If
End Sub
'--------------------------------------------------

Run the program... When you put your mouse over the picturebox, click and hold the left mouse button and drag the form....



Cheers!

0
 
raya70Author Commented:
Ok, the problem is solved, I did some weird stuff on one place that messed things up and now it works. Thankx for your time!
0
 
JuiletteCommented:
mcrider:

Cool..I knew you could move controls as well as the form but I thought the picture box would just move and not the form...
I'll add it to my collection of tips.

Wayne
0
 
mcriderCommented:
Juilette

Yea, it's the ReleaseCapture that does it... Once you call it then send the window move message, the whole window moves, not the control.

raya70

Thanks for the points! Glad I could help!



Cheers!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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