|
-
Feb 6th, 2024, 01:42 PM
#1
Thread Starter
Lively Member
[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
Last edited by Tabi; Feb 9th, 2024 at 09:20 PM.
-
Feb 11th, 2024, 04:23 AM
#2
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
-
Feb 11th, 2024, 08:44 AM
#3
Re: [VB6]. Move a Window by dragging from any part of it
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 16th, 2024, 10:48 PM
#4
Thread Starter
Lively Member
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|