I want two forms to move together when the user move one. I assume, If I knew when the main form is moved, I could move automatically the other form.
Do you have a better idea ?
Assuming that each form are from the same EXE. . .
One could monitor the coordinates of a form by using a timer in each from.
The code in the timer’s could read the other forms Top and Left properties and take appropriate action when the other forms Top / Left coordinates have changed.
RonVaught,
Thanks a lot for your suggestion, but I'm not sure this would be the best solution : the timer should verify the coordinates very often to be really efficient (I mean to obtain the second form to stick to the first one) and I'm afraid it takes to many ressources...
Why this kind of event couldn't be catched ?
You could use the MouseUp event in each form. Assuming the user used the mouse to move the form. . . When the mouse button is released set each forms coordinates accordingly. Would this work for you?
Good Idea !
... but I've ever tried, and using the mouse on the title bar to move the form does not make a MouseUp event.
MouseUp event is only throwed when the user click in the content of the form.
To do that, you have to create a hook to subclass your window with the WM_MOVE message...
Basically set the window handle of your form to your own customized message handler. Check for WM_MOVE (and move the 2nd form along with it) and pass pass the messages onto the original message handler.
Here's an example a little more relevant to want you wanted. It shows two forms and when either one is moved it moves the other one to stay "attached" to it.
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private lpPrevWndProc1 As Long
Private lpPrevWndProc2 As Long
Private hWnd1 As Long
Private hWnd2 As Long
Function WindowProc(ByVal hw As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
If hw = hWnd1 Then
If uMsg = WM_MOVE Then Form2.Move Form1.Left + Form1.Width, Form1.Top
WindowProc = CallWindowProc(lpPrevWndProc1, hw, uMsg, wParam, lParam)
Else
If uMsg = WM_MOVE Then Form1.Move Form2.Left - Form2.Width, Form2.Top
WindowProc = CallWindowProc(lpPrevWndProc2, hw, uMsg, wParam, lParam)
End If
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.