Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving the form above the screen 1

Status
Not open for further replies.

neseidus

Programmer
Sep 1, 2004
41
CA
Hi, I posted before about moving the form by clicking anywhere on the form and dragging it. This works fine but when I drag the form to have the title bar above the screen visual basic automatically snaps the window back down.

Here's the post I made before, including the code I'm using to move the window...

Does anyone know how this can be achieved?
Thanks,
-Steve
 
It is actually a safety feature, as far as I can tell, to ensure that you don't accidentally move the title bar off the screen (and thus be unable to move the window again)
 
And this safety feature is provided by Windows, not Visual Basic. However, if you use the following alternate code, you can effectively bypass this feature.

This code is essentially same as IvanMoala provided you in thread707-942042, but it has the added advantage that it can work with any ScaleMode (other than twips) selected for the form, like pixels. I think this was the reason that code was not working properly as you mentioned in the other thread.

Also note that you can make this code to work with left, right, middle or any combination of these mouse buttons by modifying the Case statement in the MouseMove event.
___
[tt]
Dim XPos As Single, YPos As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
XPos = X
YPos = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case vbLeftButton ', vbRightButton
Move Left + ScaleX(X - XPos, ScaleMode, vbTwips), Top + ScaleY(Y - YPos, ScaleMode, vbTwips)
End Select
End Sub [/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top