MDI parent and child form controls interaction.

Hi!

Can anyone give a sample C# code for a command button of a child Form to change the "text" property of the parent Form when the button is clicked

Kindly post your solution guys. Thank you.


Answer this question

MDI parent and child form controls interaction.

  • Dorsk

    This is on MDI Form's menu click

    private void menuItem2_Click(object sender, System.EventArgs e)
    {
    objForm2 = new Form2(this);
    objForm2.MdiParent = this;
    objForm2.Show();
    }

    When you instantiate Form2, you past your MDI reference also

    This is on your child form :

    private Form1 mdiForm;

    public Form2(Form1 pMdiForm)
    {
    InitializeComponent();
    mdiForm = pMdiForm;

    }

    private void button1_Click(object sender, System.EventArgs e)
    {
    mdiForm.Text = "Change";
    }





  • Ali Khan

    compaks wrote:
    This is on MDI Form's menu click

    private void menuItem2_Click(object sender, System.EventArgs e)
    {
    objForm2 = new Form2(this);
    objForm2.MdiParent = this;
    objForm2.Show();
    }

    When you instantiate Form2, you past your MDI reference also

    This is on your child form :

    private Form1 mdiForm;

    public Form2(Form1 pMdiForm)
    {
    InitializeComponent();
    mdiForm = pMdiForm;

    }

    private void button1_Click(object sender, System.EventArgs e)
    {
    mdiForm.Text = "Change";
    }




    Thnaks a lot! Passing data (such as text) between forms is very tricky in C#. I'm used to program in VB6 and now I'm try the OOP. :)

  • MDI parent and child form controls interaction.