Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
Have an application that has an application launcher and a wmi section to it and i want to have both forms displaying at the same time but be connected to each other. I found the below code and when i move form2 it locks form 1 to it but when i try and reverse it for form one it dosent work. Please help with this im lost.

VB
Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move, Me.Layout
        If Me.Focused Then
            form2.Left = Me.Right
            form2.Top = Me.Top
        End If
    End Sub
'on Form2:
Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move, Me.Layout
        If Me.Focused Then
            Form1.Left = Me.Left -Form1.Width
            Form1.Top = Me.Top
        End If
    End Sub
Posted
Comments
lewax00 20-Jul-12 14:02pm    
"it dosent work" isn't very descriptive. What exactly doesn't work?
Zachary.shupp 20-Jul-12 14:15pm    
This works but it still lets me seperate the 2 forms. I want them to stay together unles you click the red x on the form.
lewax00 20-Jul-12 14:23pm    
So why not make them one form? This seems like a lot of work to accomplish the same thing.
Sergey Alexandrovich Kryukov 20-Jul-12 15:09pm    
Sure. This is a bad design, nothing else -- please see my answer.
--SA
Sergey Alexandrovich Kryukov 20-Jul-12 16:04pm    
Figured it out? Not good. And you even formally accepted your own answer... funny. Listen to a good friendly advice: don't do it. Think of a nice UI design.
--SA

If you feel that you really need it, it tells me that your UI design is not good. You should revise it. You are not supposed to prevent the user from doing something with is the part of user's natural rights: arrange individual top-level windows the way they want.

If I saw such behavior, for me, this is the clear message to stop using your program and any your products. Believe me, many user would feel the same. Review your design.

—SA
 
Share this answer
 
Comments
Espen Harlinn 21-Jul-12 13:59pm    
Good points
Sergey Alexandrovich Kryukov 22-Jul-12 14:33pm    
Thank you, Espen,
--SA
I think you'll find that the active form is not focussed, and yes that does that sound crazy. What will be happening is that a child control on the form has the focus.

One solution would be to use the ContainsFocus property but an alternative, which is better, as you are not actually interested in the input focus, is to use the ActiveForm property. It's a shared property so use ActiveForm on it's own rather than Me.ActiveForm.

e.g.
VB
If ActiveForm = Me Then
    Form1.Left = Me.Left -Form1.Width
    Form1.Top = Me.Top
End If


Alan.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900