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.
raya70Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.