tags:

views:

32

answers:

2

Hi, everybody.

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!

+2  A: 

Set the Form.MdiParent property on form3:

form3.MdiParent = this.MdiParent;
adrift
In which block of code should I change this property?
sturmgewehr
I think if I add such property - form3 will be the parent of form2, not form1 as i need
sturmgewehr
the 'this' above is the instance of Form2, and its MdiParent property points to Form1, so this should set form3's MdiParent to point to form1 also.
adrift
I understand now, it works. thanks!
sturmgewehr
You're welcome... so I answered your question? ;)
adrift
yes, sure :) tnx
sturmgewehr
I would greatly appreciate it if you be kind enough to mark my answer as the accepted answer... thanks :)
adrift
+1  A: 

form3.MdiParent = this.MdiParent

jalexiou