Tow forms move together?

How to make form2 remain the same position related with form1 when the user moves form1? I don't want to use MDI child form :-)
learnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mark2150Commented:
In the form#1 repaint event set Form2's Top & Left to match Form1's.

M
0
learnAuthor Commented:
To mark2150:

That is an interesting idea but not always success ;-( Even in the success cases, form2 move to the place only after form1 stopped moving.
0
learnAuthor Commented:
Adjusted points to 55
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

amebaCommented:
You will have to subclass your form to catch WM_MOVING (and WM_SIZING) messages. It is not worth the efforts, and it won't work on all computers (users can switch off this new window style and you won't receive messages)
0
mark2150Commented:
It's kind of hard to know where to put the 2nd form until the first stops moving!

You can do some stuff with making the 2nd forms .VISIBLE property FALSE at the start of move and then TRUE once it's been shifted.

M
0
mcriderCommented:
Ameba is right about not being able to catch WM_MOVING/WM_SIZING on all systems, however here's an idea that will work on all systems... It's kind of bizzare, but bear with me.

Let's say you have 2 forms... FORM1 and FORM2. You want FORM2 to "snap" to an associated position of FORM1 when you move FORM1.

First, in a new project, create FORM1 without a Title Bar.
you can do this my setting the following FORM1 Properties at build time:

     .Caption=""
     .ControlBox=False
     .MinButton=False
     .MaxButton=False

Then create your own "Title Bar" using a PictureBox.  You can duplicate all of the functionality of an existing title bar, but for this example, you don't have to.  Just put a PictureBox at the top of form1 that's about the same height as a titlebar and stretch it across the form.

Add a blank FORM2 to your project.

Add the following code to FORM1:




      Private Declare Function SendMessage Lib "User32" _
                         Alias "SendMessageA" (ByVal hWnd As Long, _
                                               ByVal wMsg As Long, _
                                               ByVal wParam As Long, _
                                               lParam As Any) As Long
      Private Declare Sub ReleaseCapture Lib "User32" ()
      Const WM_NCLBUTTONDOWN = &HA1
      Const HTCAPTION = 2
Private Sub Form_Load()
    Form2.Left = Form1.Left + Form1.Width + 300
    Form2.Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim lngReturnValue As Long
   If Button = 1 Then
      Call ReleaseCapture
      lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
      Form2.Top = Form1.Top
      Form2.Left = Form1.Left + Form1.Width + 300
   End If
End Sub




Run the program.  When you drag FORM1 around by your fake title bar, FORM2 will "snap" to it's associated location.


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
learnAuthor Commented:
Hi mcrider,

That is really a clever method for solving my problem!

I tried to change a little bit but without success ;-) I move two lines in your code to the mouseup event.....Can you also tell me what is wrong:

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ReleaseCapture
    Form2.Top = Form1.Top
    Form2.Left = Form1.Left + Form1.Width + 300  
End Sub

Cheers.
0
learnAuthor Commented:
Thank you for your Excellent comment which is an answer now ;-)

I think I naven't understand the API functions :-( Can you tell me what they are doing?
0
mcriderCommented:
You are missing the SendMessage API in the example you sent back:

     lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)

It goes after the ReleaseCapture function.
     
The ReleaseCapture function releases the mouse capture from a window in the current thread and restores normal mouse input processing. A window that has captured the mouse receives all mouse input, regardless of the position of the cursor, except when a mouse button is clicked while the cursor hot spot is in the window of another thread. Basically, it "cleans" up the thread.

The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.

The two calls in combination tell the system to clean up the thread and start the window procedure to move the window.

By the way, did you get the example I gave you to work??

Cheers!
0
mcriderCommented:
The other thing is you don't want to do this in the mouseup event, because it doesnt start the drag function until after the mouse has been released.


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.