Call form (parent): Form1, called form (sub): Form2
Method 1: Ownership law
Form1:
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
When calling Form2, set the owner of the Form2 to Form1
Form2 F2 = new Form2 ();
F2. Owner = this;
F2. ShowDialog ();
Form2:
When it is necessary to refresh its caller (parent)
Form1 F1;
F1 = (Form1) this. Owner;
F1. Refresh_method ();
Method 2: Self-transfer method
Form1:
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
Form2 F2 = new Form2 ();
F2. ShowDialog (this);
Form2:
Private Form1 p_f1;
Public Form2 (Form1 F1)
{
InitializeComponent ();
P_F1 = F1;
}
When refreshed
P_f1. Refresh_method ();
Method 3: Attribute method
Form1:
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
When called
Form2 F2 = new Form2 ();
F2. P_F1 = this;
F2. Show ();
Form2:
Private Form1 p_f1;
Public Form1 p_f1
{
Get{return p_f1;}
SET{P_F1 = value;}
}
When refreshed
P_f1. Refresh_method ();
Method 4: Delegate method
Form1:
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
When called
Form2 F2 = new Form2 ();
F2. Showupdate + = new Displayupdate (Refresh_method);
F2. Show ();
Form2:
Declaring a delegate
public delegate void Displayupdate ();
declaring events
public event Displayupdate Showupdate;
When refreshed, put in an event that needs to perform a refresh
Showupdate ();
Method 5: Message method
Form1
Need to have a public refresh method
public void Refresh_method ()
{
//...
}
Judging dialog box results
if (Form1.showdialog (this) ==dialogresult.ok)
{
Refresh_method ()
}
From2
When refreshed
This. DialogResult = System.Windows.Forms.DialogResult.OK;
C # WinForm Subform Refreshes all method summaries of the parent form