Users Pricing

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 User 8551 01 Aug 2010 Updated 07 Sep 2019

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.

    public int num
        {
            get
            {
                return 5;
            }
            set
            {
                num = value;
            }
        }
public int 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 = new frmBrowse();
private void 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



I am a content writter !


2 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md