How to pass string value from one form to another form’s load event in C #

Just create a property on the Form2 class and set it before you show Form2.

public class Form2
{
   ...
   public string MyProperty { get; set; }

   private void Form2_Load(object sender, EventArgs e)
   {
       MessageBox.Show(this.MyProperty);
   }
}

From Form1:

public void button1_Click(object sender, EventArgs e)
{
    string departmentName = "IT";
    Form2 frm2 = new Form2();
    frm2.MyProperty = departmentName;
    frm2.Show();
    this.Hide();
}

Leave a Comment