Send values from one form to another form

后端 未结 19 2542
眼角桃花
眼角桃花 2020-11-21 11:45

I want to pass values between two Forms (c#). How can I do it?

I have two forms: Form1 and Form2.

Form1 contains one button. When I click on that button, Fo

19条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 12:02

    Constructors are the best ways to pass data between forms or Gui Objects you can do this. In the form1 click button you should have:

    Form1.Enable = false;
    Form2 f = new Form2();
    f.ShowDialog();
    

    In form 2, when the user clicks the button it should have a code like this or similar:

    this.Close();
    Form1 form = new Form1(textBox1.Text)
    form.Show();
    

    Once inside the form load of form 1 you can add code to do anything as you get the values from constructor.

提交回复
热议问题