Skip to content

Passing value from one form to other

Zeb Rehman

Asked May 20, 2011, 11:32 PM EDTSolved
Share
LinkedInX
Hi everybody, Please can some body tell me how can i pass int value from one form to another in windows form application using c-sharp......................

                                                       Thanks in advance                                                        

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    1) Create a public property in the form2.
    2) From the Form1, create instance of the FOrm2,and assign the value for the public property.

    Form 1 Code : 
    private void button2_Click(object sender, EventArgs e)
    {
                Form2 frm = new Form2();
                frm.MyName = "From Form 1";            
                frm.ShowDialog();
    }

    Form 2 Code : 

    public string MyName
    {
     get;
     set;
    }
    For this I have attached the sample project.

    Another way,you can create a static class and assign the values into in Form1 . Then can access the values into form2.

    Kindly let me know,still if you need any help.
    0
  • 0
    Thanks Murali bro that really helped me
    0