将Form2的textBox2的值设置给Form1的textBox1
并关闭Form2
- public partial class Form1 : Form {
- public Form1() {
- InitializeComponent(); }
- public string TextBox1Text {
- set { this.textBox1.Text = value; } get { return this.textBox1.Text; }
- } private void button1_Click(object sender, EventArgs e)
- { Form2 frm2 = new Form2();
- frm2.Show(this);//或 frm2.ShowDialog(this); ////或者
- //Form2 frm2 = new Form2(); //frm2.Owner = this;
- //frm2.Show();//或 frm2.ShowDialog(); }
- } public partial class Form2 : Form
- { public Form2()
- { InitializeComponent();
- } private void button2_Click(object sender, EventArgs e)
- { Form1 frm1 = (Form1)this.Owner;
- frm1.TextBox1Text = this.textBox2.Text; this.Close();
- } }
希望本文所述对大家的C#程序设计有所帮助。










