0% found this document useful (0 votes)
32 views

Methods To Pass Data Between Forms in Windows Application

There are four main ways to pass data between forms in a Windows application: 1) Using a Constructor to pass data when instantiating a new form, 2) Using Objects by creating an object in one form and accessing it in another, 3) Using Properties by defining public properties in one form to access in another, and 4) Using Delegates to define callback methods that can pass data between forms. The document then provides an example of using a constructor, where a string is passed from a textbox in Form1 to a label in Form2 when Form2 is instantiated from a button click in Form1.

Uploaded by

api-26891935
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Methods To Pass Data Between Forms in Windows Application

There are four main ways to pass data between forms in a Windows application: 1) Using a Constructor to pass data when instantiating a new form, 2) Using Objects by creating an object in one form and accessing it in another, 3) Using Properties by defining public properties in one form to access in another, and 4) Using Delegates to define callback methods that can pass data between forms. The document then provides an example of using a constructor, where a string is passed from a textbox in Form1 to a label in Form2 when Form2 is instantiated from a button click in Form1.

Uploaded by

api-26891935
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

There are so many methods to pass data between forms in windows

application. let me take four important (easiest) ways of accomplishing this.

1.Using Constructor
2.Using Objects
3.Using Properties
4.Using Delegates

Constructor approach:

Step 1: Code a constructor for Form2 class as below

Public Form2(string strTextBox)


{
InitializeComponent();
label1.Text = strTextBox;
}

Step 2: Instantiate Form2 class in Form1 button click event as below

Private void button_Click(object sender System.EventArgs e)


{
Form2 frm = new Form2(textbox1.Text);
Frm.Show();

You might also like