[VB6]. Move a Window by dragging from any part of it
Good morning. I want to share this simple code. It allows the user to move the window, by clicking and dragging, from any point on the Form.
The scrolling achieved is smooth and pleasant, just as if the click had been on the title bar.
With almost no code, it provides elegant functionality.
Also useful when the Window Title Bar is higher up the screen. In this case, the Form can be downloaded by fishing it from any point on it.
You can also make the call from the MouseMove Event of a Control Frame. In this case, clicking on it and dragging moves the Form.
You could even put it in the MouseMove Event of any particular control, achieving the same effect, moving the form to any part of the screen. [/B]
Please, if you implemented it, comment if you liked it or not. This is a translation from Spanish, sorry if the reading is not pleasant. Thank you
.
In each Form to move:
Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)FormMove Me, Button, X, Y
End Sub
In a module:
Static Sub FormMove(Formulario As Form, Button As Integer, X As Single, Y As Single)Dim MemX As Single, MemY As Single, YaMovio As Boolean, AchFrm As Single
AchFrm = Formulario.Width
If Button = 1 Then
If Not YaMovio Then YaMovio = True: MemX = X: MemY = Y
Formulario.Left = Formulario.Left + X - MemX
Formulario.Top = Formulario.Top + Y - MemY
Else
End If
End Sub
Re: [VB6]. Move a Window by dragging from any part of it
A shorter and more generic variant would be (also supporting Controls):
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveFrmOrCtl Me, Button, X, Y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveFrmOrCtl Picture1, Button, X, Y
End Sub
Sub MoveFrmOrCtl(FrmOrCtl As Object, Button As Integer, X As Single, Y As Single)
Static X0 As Single, Y0 As Single
If Button <> 1 Then X0 = X: Y0 = Y Else _
FrmOrCtl.Move FrmOrCtl.Left + X - X0, FrmOrCtl.Top + Y - Y0
End Sub
Olaf
Re: [VB6]. Move a Window by dragging from any part of it
Re: [VB6]. Move a Window by dragging from any part of it
Thank you very much for improving the code!
I hope, later, I can upload something more useful.