Sending information between SDI C# Forms.
To send information or accessing functions from one form to another is easy with
.NET Windows Forms.
Create an empty C# Windows Forms project. On Form1, add a Button control and a Textbox
control. Set the TextBox control to public access using the public keyword or in
the properties set the Modifiers to public. In the Solutions Explorer create a second
form named Form2 and add a single button control to form2.
On the Form1 button control click event add the following code.
Form2 form2 = new Form2();
//The following line adds form2 to the collection of owned forms, owned by form1.
this.AddOwnedForm(form2);
//Call and show the form.
form2.Show();
On Form2 's button click event add the following code.
//Create a reference to form1.
Form1 form1 = (Form1)this.Owner;
//Set the text value for form1 textbox1.
form1.textBox1.Text = "Transfer Text";
Run the project and you can see just how easy it is to send information between
SDI forms.
Sending information between MDI C# Forms.
To send information or accessing functions from the MDI form to child forms is easy
with .NET Windows Forms.
Create an empty C# Windows Forms project. On Form1 set the IsMdiContainer to true,
add a Button control and a Textbox control to the form. Set the TextBox control
to public access using the public keyword or in the properties set the Modifiers
to public. In the Solutions Explorer create a second form named Form2 and add a
single button control to form2.
On the Form1 button control click event add the following code.
Form2 form2 = new Form2();
//Set Form2's MdiParent to Form1.
form2.MdiParent = this;
//Call and show the form.
form2.Show();
On Form2 's button click event add the following code.
//Create a reference to form1.
Form1 form1 = (Form1)this.MdiParent;
//Set the text value for form1 textbox1.
form1.textBox1.Text = "Transfer Text";
|
|