C#如何用FORM1显示FORM2,然后将FORM2中的TEXTBOX中的值返回给FORM1?
来源:百度知道 编辑:UC知道 时间:2024/06/01 18:15:17
form1 里面建个label1 和一个button1
解决方案资源管理器
添加个新建项 windows窗体 叫FORM2
里面放个 TEXTBOX1和一个button1
下面是代码
form1里面
---------------------
// button1_Click事件
private void button1_Click(object sender, EventArgs e)
{
{
Form2 fm2 = new Form2();
fm2.ShowDialog();
{
label1.Text = fm2.Str;
}
}
}
-----------------
form2里面
-------------
// 添加个属性
private string _str;
public string Str
{
get { return this._str; }
set { this._str = value; }
}
//button_click 事件
private void button1_Click(object sender, EventArgs e)
{
Str = textBox1.Text;