C # WinForm Subform Refreshes all method summaries of the parent form

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.