Send values from one form to another form

后端 未结 19 2496
眼角桃花
眼角桃花 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:14

    declare string in form1 public string TextBoxString;

    in form1 click event add

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

    in form2 constructer

    public Form2(ref Form1 form1handel)
        {
            firstformRef = form1handel;
            InitializeComponent();
        }
    

    in form2 crate variable Form1 firstformRef;

    private void Submitt_Click(object sender, EventArgs e)
        {
            firstformRef.TextBoxString = textBox1.Text;
            this.Close();
            firstformRef.Show();
    
        }
    

提交回复
热议问题