The rigjh
The rigjh

Reputation: 67

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.

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;
        }
    }

Upvotes: 2

Views: 41

Answers (1)

Caius Jard
Caius Jard

Reputation: 74700

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

Upvotes: 1

Related Questions