Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Keep both forms on top

I have 2 forms (Parent & child). i want to keep both on top (Not topMost). The next fragment work’s but the parent not firing any event. I found this "Click Event Not Firing – Cannot Change Focus – Cannot Close Form" althouhg this did not work.

The next fragment works for keep forms but parent doesn’t not work:

public FormMain()
{
   InitializeComponent();
   this.Activated += FormMain_Activated;
} 

private void FormMain_Activated(object sender, EventArgs e)
{
   ChildForm.Activate();
}

I tried focus the parent form on "GotFocus" and "Activated" althought this doesn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Note: For child form i have this fragment:

        protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            // turn on WS_EX_TOOLWINDOW style bit
            cp.ExStyle |= 0x80;
            return cp;
        }
    }

>Solution :

The behavior you’re describing is that of an owned form; something like a floating tool panel in a paint program, that should minimize/restore when the main window it is associated with does a minimize/restore, but can be moved independently and be covered by otehr windows when the main paint program is also covered

To do that, you can make the main form an owner of the tool panel form. If the main form is responsible for opening the tool panel:

toolPanel.Show(this);   //the code is in the main form so `this` refers to the current instance of the main form

If some other form is responsible for showing both, it’d be more like toolPanel.Show(mainForm) – we pass to Show the form that we want to dedicate as the owner of the form we are showing

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading