C# Calling a method from another Form

后端 未结 4 1313
清酒与你
清酒与你 2020-12-17 07:24

Hi I have 2 Form Form1 and Form2

Form1 have a table and there is my records and there is a Void for refresh the table in the Form1.

Form2 is my insert form I

4条回答
  •  眼角桃花
    2020-12-17 07:43

    Form2 will have to have a reference to the instance of Form1. You can pass this reference to Form2 when the insert button is clicked:

    Form2 insertForm = new Form2();
    //Form2.ShowDialog(Me); - Correction - 'Me' is for VB. in C# it's:
    Form2.ShowDialog(this);
    

    Next on Form2 you can access Form1 like this:

    (Form1)this.Parent.RefreshTable();
    

提交回复
热议问题