When New Form2 in Form1, New Form2 (this), the Form1 is accepted in the form of Form1 in the constructor, and then a FROM1 variable accepts parameters can be used, you can use Form1, you want to use the controls They defined them into public in Form1. Form1: using system.drawing; using system.collections; using system.componentmodel; using system.data; using system.data;
namespace f2parent {/// /// Summary description for Form1 /// summary> public class Form1: System.Windows.Forms.Form {public System.Windows.Forms.TextBox textBox1; private System.Windows. . Form.Button Button1; /// /// Required designer variable. /// summary> private system.componentmodel.container components = null;
Public form1 () {/// Required for Windows Form Designer Support // InitializationComponent ();
// // Todo: add any constructor code after initializationcomponent call //}
/// /// clean up any resources being used. /// summary> protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {components.dispose () }} Base.Dispose (Disposing);
#region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor /// summary> private void InitializeComponent (). {This.TextBox1 = new system.windows.forms.textbox (); this.button1 = new system.windows.Forms.Button (); this.suspendlayout (); // // textbox1 // this.textbox1.location = New system.drawing.point (16, 32); this.TextBox1.name = "textbox1"; this.textbox1.tabindex = 0; this.textBox1.text = "textbox1"; // // button1 // this.button1 .Location = new system.drawing.point (88, 128); this.button1.name = "button1"; this.button1.tabindex = 1; this.button1.text = "button1"; this.button1.click = New system.eventhandler (this.button1_click); // // form1 // this.autoscalebasesize = new system.drawing.size (5, 12); this.clientsize = new system.drawing.size (292, 266); this .Controls.add (this.button1); this.Controls.add (this.textbox1 This.ismdicontAiner = true; this.name = "form1"; this.text = "form1"; this.ResumeLayout (false);} #ENDREGION
/// /// the main entry point for the application. /// summary> [stathread] static void main () {Application.run (new form1 ());}
private void button1_Click (object sender, System.EventArgs e) {Form2 frm2 = new Form2 (this); frm2.ShowDialog ();}}} form2using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.windows.forms;
Namespace F2Parent {/// /// summary description for form2. /// summary> public class form2: system.windows.Forms.form {private system.windows.forms.button button1; /// < summary> /// Required designer variable /// summary> private System.ComponentModel.Container components = null;. private Form1 form1; public Form2 (Form1 frm1) {// // Required for Windows Form Designer support // InitializeComponent (); FORM1 = FRM1;
// // Todo: add any constructor code after initializationcomponent call //}
/// /// clean up any resources being used. /// summary> protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {components.dispose () }} Base.Dispose (Disposing);
#region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor /// summary> private void InitializeComponent (). {This.Button1 = new system.windows.Forms.Button (); this.suspendlayout (); // // button1 // this.button1.location = new system.drawing.point (184, 192); this.button1 .Name = "button1"; this.button1.tabindex = 0; this.button1.text = "button1"; this.button1.click = new system.eventhandler (this.button1_click); // // form2 // this .Autoscalebasesize = new system.drawing.size (5, 12); this.clientsize = new system.drawing.size (292, 266); this.Controls.add (this.button1); this.name = "form2"; THIS.TEXT = "Form2"; this.ResumeLayout (false);
} #Endregion