How do I pass data from child of child form to parent form in C#?

后端 未结 3 1971
暖寄归人
暖寄归人 2021-01-21 02:42

I am new to c#. I have the following in my project in windows forms:

Form1 with button and DataGridView.

Form2 with button.

Form3 with button and 3 text

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-21 03:14

    You can pass owner to method Show() for new forms. Then you can get owner form from Owner property.

    private void buttonOpenForm2 _Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2();
        frm2.Show(this);
    }
    

    So you can get Form1:

    (Form1)frm2.Owner
    

    and call public method of Form1 class and pass there your new data.

提交回复
热议问题