VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Move forms together

by Andre Koester (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Move forms together as if they were docked.
No Timer needed!
I had to separate forms used as a kind of toolbox. My idea was, that it would be nice if I could move these two together if they were both active. VB doesn't tell me when my form is moved. But then I realised that I read s.th. about moving forms without a titlebar. Using this trick my code will perform the following action:
1. The form detects a mousedown event
2. The mouse is released and the form moved by FormDrag
3. The other form is notified of the movement
4. The other form will follow the first
Don't forget to vote if you like it ;o)

API Declarations
Declare Sub ReleaseCapture Lib "user32" ()
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Rate Move forms together

'Put this in a global module
Public Sub FormDrag(TheForm As Form)
  ReleaseCapture
  Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)
End Sub
'this code has to be in your form
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  FormDrag Me 'move form
  NameOfOtherForm.MoveMe 'notify other form
End Sub
'this is needed in the second form
Public Sub MoveMe()
  If Top > NameOfOtherForm.Top Then
    Top = NameOfOtherForm.Top + NewFrm.Height 'Place below other form
    Left = NameOfOtherForm.Left
  Else
    Top = NameOfOtherForm.Top - Height     'Place above other form
    Left = NameOfOtherForm.Left
  End If
End Sub

Download this snippet    Add to My Saved Code

Move forms together Comments

No comments have been posted about Move forms together. Why not be the first to post a comment about Move forms together.

Post your comment

Subject:
Message:
0/1000 characters