Search Tools Links Login

Move forms together


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)

Original Author: Andre Koester

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

Code

'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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 66 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.