C# winform form之间传值(本人亲测)(2)

一、父窗体向子窗体传值

C# winform form之间传值(本人亲测)(2)_第1张图片

父窗体中代码:

private void btn_father_Click(object sender, EventArgs e)
        {
            Child child = new Child();
            child.child_text = tb_father.Text;
            child.ShowDialog();
        }

子窗体中代码:

 public string child_text { get; set; }

        private void btn_child_Click(object sender, EventArgs e)
        {
            child_text = tb_child.Text;
            this.Close();
        }

        private void Child_Load(object sender, EventArgs e)
        {
            tb_child.Text = child_text;
        }

二、子窗体向父窗体传值

C# winform form之间传值(本人亲测)(2)_第2张图片

父窗体中代码:

 private void btn_father_Click(object sender, EventArgs e)
        {
            Child child = new Child();
            child.ShowDialog();
            tb_father.Text = child.child_text;
        }

子窗体中代码:

 public string child_text { get; set; }

        private void btn_child_Click(object sender, EventArgs e)
        {
            child_text = tb_child.Text;
            this.Close();
        }


你可能感兴趣的:(.Net)