articles

Home / DeveloperSection / Articles / HOW TO PASS VALUE FROM ONE FORM TO ANOTHER FORM

HOW TO PASS VALUE FROM ONE FORM TO ANOTHER FORM

Anonymous User7963 01-Aug-2010

To pass value from one form to another we have to add a property in the form from which we want to send data. To set property we have to write the following code. Let us say this is form2.

 publicint num
        {
            get
            {
                return 5;
            }
            set
            {
                num = value;
            }
        }
publicint num1
        {
            get
            {
                return 15;
            }
            set
            {
                num1 = value;
            }
        }

 

The code above will return 5 when the property when it is called from form1. To call the property from form1 we have to write the collowing code in form1.

int n = form2.num;

Example

Here br is object of form2 (browse form).

frmBrowse br = newfrmBrowse();
privatevoid btnBrowse_Click(object sender, EventArgs e)
        {          
            br.ShowDialog();
            txtId.Text = br.num;
            txtName.Text = br.num1;
           
            panel1.Enabled = true;           
        }

HOW TO PASS VALUE FROM ONE FORM TO ANOTHER FORM

Here form2 in Browse form. When any cell is clicked in data grid of this form the record will be transferred from this form to Record form (i.e. Form1).

HOW TO PASS VALUE FROM ONE FORM TO ANOTHER FORM



Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By