Friday, October 9, 2009

Passing Dynamic Values From One Form to Another in C#

---------------------------------------
//write this code in form1
private void btnPassValue_Click(object sender, EventArgs e)
{
   frmSecondForm myForm2 = new frmSecondForm();
   myForm2.form1TextBoxValue = this.txtPassValue.Text;
   myForm2.Show();
}
------------------------------------------
//write this code in form 2

//form level
private string tempvalue;
public string form1TextBoxValue
{
    get
    {
       return tempvalue;
    }
    set
    {
       tempvalue = value;
    }
}
private void frmSecondForm_Load(object sender, EventArgs e)
{
    this.txtReceiveValue.Text = tempvalue;
}
------------------------------------------
***end of program***

No comments:

Post a Comment