在Form1中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public partial class Form1: Form { Form2 form2; private void button1_Click( object sender, EventArgs e) { if (form2 == null ) form2 = new Form2(); form2.Show( ); } private void button2_Click( object sender, EventArgs e) { //点击button2获取form2中textBox1的内容 if (form2 == null ) return ; string s = form2.Message; //详见Form2类中的定义 } } |
在 Form2中
1
2
3
4
5
6
7
8
|
public partial class Form2: Form { //添加Message public string Message { get { return textBox1.text;} } } |