C#窗口间传值的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 10:53:57
Form2 的 TextBox1输入 ,点击 按钮 ,然后 FORM1 Label1.Text 赋值为 Form2 的 TextBox1

我设置 Form2 的 TextBox1 为 PUBLIC,但为什么 运行 无法 获取

Form2按钮事件下这么写
Form1 f = new Form1(textBox1.Text);
f.Show();
Form1下加个构造方法.
先声明一个变量 public string aa;
public Form1(string aa)
{
this.aa = aa;
InitializeComponent();
}
加载事件下加这个
this.label1.Text = aa;

1.为Form2定义一个public static string textValue;
2.点击按钮的时候将textValue的值设为Form2.TextBox1.Value;
3.在Form1_Load中,将Form1.Label1.Text设为Form2.textValue

只在asp.net中用过传值。

为Form2添加带参的构造函数,在构造函数中赋值,通过new Form(string value)传值。