KJSR
KJSR

Reputation: 1757

Taskbar icon opens the wrong Active form

Having a strange behaviour with my application whereby when navigation between web browser (or any other application) and clicking back into the application seems to open the wrong Form? So user literally has to make use of Tab window to open the correct Form.

For e.g. Form1 is the main form. User clicks a button which opens Form2. Form1 is hidden behind the scene while Form2 opens. Now if user goes to a different application e.g. browser and clicks back into the application Form1 is displayed and there is no other way of going back to Form2 without the Tab window?

I have used the .ShowDialog() property when opening Form2 which disabled the parent form Form1 but still seems to do it occasionally?!?

I have also set the ShowInTaskBar for Form2 to False so that there is one icon in taskbar for all forms.

Not really sure what can cause this behaviour to happen?

private void button1_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    form2.ShowDialog();
}

Upvotes: 0

Views: 57

Answers (2)

Roberto Pegoraro
Roberto Pegoraro

Reputation: 1487

When you open form2, you need set mdiParent of form1.

First, set form1 as "isMdiParent" to "true" in properties, and then use the follow code:

private void button1_Click(object sender, EventArgs e)
{
    Form2 form2 = new Form2();
    form2.MdiParent = this;
    form2.Show();
}

Upvotes: 0

Bart
Bart

Reputation: 26

I think you need to tell Form2 who its owner form is.

Like this:

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 form2 = new Form2();
        form2.Owner = this;
        form2.ShowDialog();
    }

see System.Windows.Forms for more information

Upvotes: 1

Related Questions