Abdu Abdul

Abdu Abdul

  • 1.3k
  • 409
  • 15k

Passing Data from FormA to FormB

Dec 29 2023 7:03 PM

I am trying to pass data from FormA to FormB, if i tried normal method it worked fine, but when i tried closing the FormA after when passing data to FormB the data dosent get passed 

What i have tried:

FormA

private void button1_Click(object sender, EventArgs e)
{

    //This don't pass the data
    this.Close();
    th = new Thread(() => open_FormB(value_lbl.Text.Trim()));
    th.SetApartmentState(ApartmentState.STA);
    th.Start();

    //This don't pass the data as well

    this.Close();
    th = new Thread(() =>
    {
        FormB Form_b = new FormB(value_lbl.Text.Trim());
        Form_b.ShowDialog();
    });
    th.SetApartmentState(ApartmentState.STA);
    th.Start();

    //This Worked Fine
    FormB F = new FormB(value_lbl.Text);
    F.Show();
}

private void open_FormB(string email)
{
    Application.Run(new FormB(email_lbl.Text));
}

FormB

public FormB(string value)
{
    InitializeComponent();
    label10.Text = value;
}

Please help out


Answers (7)