Send values from one form to another form

后端 未结 19 2519
眼角桃花
眼角桃花 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条回答
  •  不知归路
    2020-11-21 12:13

    You can use this;

    Form1 button1 click

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2();
        this.Hide();
        frm2.Show();
    }
    

    And add this to Form2

    public string info = "";
    

    Form2 button1 click

    private void button1_Click(object sender, EventArgs e)
    {
    
        info = textBox1.Text;
        this.Hide();
        BeginInvoke(new MethodInvoker(() =>
        {
            Gogo();
        }));
    }
    
    public void Gogo()
    {
        Form1 frm = new Form1();
        frm.Show();
        frm.Text = info;
    }
    

提交回复
热议问题