Click here to Skip to main content
11,502,821 members (60,929 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET WinForm
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.

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 20-Jul-12 7:47am
Comments
lewax00 at 20-Jul-12 14:02pm
   
"it dosent work" isn't very descriptive. What exactly doesn't work?
Zachary.shupp at 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 at 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 at 20-Jul-12 15:09pm
   
Sure. This is a bad design, nothing else -- please see my answer.
--SA
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Espen Harlinn at 21-Jul-12 13:59pm
   
Good points
Sergey Alexandrovich Kryukov at 22-Jul-12 14:33pm
   
Thank you, Espen,
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
If ActiveForm = Me Then
    Form1.Left = Me.Left -Form1.Width
    Form1.Top = Me.Top
End If

Alan.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100