窗体设计时经常会用到父、子窗体之间传值。这里和大家一起分享一下:
    父窗体调用代码:
 
   Form2 form2=new Form2();//用于调用子窗体
   private void button1_Click(object sender, EventArgs e)
   {
            if (form2.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text= form2.A;//将子窗体值赋予 textBox1
            }
   }
 
    子窗体参考代码:
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public string A;
        private void button1_Click(object sender, EventArgs e)
        {
            A = textBox1.Text;
            this.DialogResult = DialogResult.OK;
            this.Hide();
        }
    }