Method One: (Form2 calls the method in Form1: The called name is set in the called form) 1, first set the main form in the main window can be called the name, set its own name of "S". This allows you to invoke the main form's method using "S" in other forms. public static Form1 s = null; Public Form1 () {InitializeComponent (); s = this;//define main form}
2. Write the method that can be called in the main window, and note that the property is set to public.
public void Setform1value () {//code required to implement the function ...}
3. For example, the Button1 button in the Form2 form needs to call Form1 's Setform1value () method, the code is as follows:
private void Button1_Click (object sender, EventArgs e) {form1.s.setform1value ();//Call Method of Form1}
Method Two: (Form2 call method in Form1: called Name setting in Form2)
1, Form2 in the code:
private form1 f ;//Set called name public form2 (form1 f) { InitializeComponent (); this. f=f; } private Void btn2_click (object sender, eventargs e) { f.setform1value ();//Call method in Form1 }
2, Form1 in the code:
Public Form1 () {InitializeComponent (); }private void Btn1_click (object sender, EventArgs e) {new Form2 (this). Show (); Show Form2 Form}
This article is from the "book to Time Square hate" blog, please be sure to keep this source http://7798914.blog.51cto.com/7788914/1653012
Winform Summary of method calls between different forms