sturmgewehr
sturmgewehr

Reputation: 11

Open child windows from another child windows in MDI

I have some problems during MDI application development using Windows Forms.

Imagine small test application with 3 forms: Form1, Form2 and Form3. Form1 is an MdiContainer (with attached menuStrip element with single botton - for test purposes). Form2 contains only single button. Form2 openes by the click on Form1 menuStrip button. Form3 should open by Form2 button click.

I've already used google for this trouble, but nothing helpful.

My code is below:

Form1

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

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

Form2

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form3 form3 = new Form3();
        form3.Show();
    }
}

Form3 actually has no code at all.

It is quite obvious that I have somehow declare that Form3 should be Form1 child but how? :)

Thanks in advance!

Upvotes: 0

Views: 2812

Answers (2)

John Alexiou
John Alexiou

Reputation: 29274

form3.MdiParent = this.MdiParent

Upvotes: 2

Jeff Ogata
Jeff Ogata

Reputation: 57823

Set the Form.MdiParent property on form3:

form3.MdiParent = this.MdiParent;

Upvotes: 4

Related Questions