#region 变量定义
Form1 frm = new Form1();
private void button4_Click(object sender, EventArgs e)
{
if (frm.textBox3.Text == "1" )
{
this.Hide();
Form2 F2 = new Form2();
F2.Show();
}
else if (frm.textBox3.Text == "2" )
{
this.Hide();
Form3 F3 = new Form3();
F3.Show();
}
}
}
}
#endregion
我在 Form1.Designer.cs中将Textbox3设置为Public
public System.Windows.Forms.TextBox textBox3;
但是还是无法成功实现,求解答?
你在Form1 中定义一个公共属性,如
public string TextVal
{
//这为文本框
get{ return textBox3.Text;;}
}
if (frm.TextVal== "1" )
{
this.Hide();
Form2 F2 = new Form2();
F2.Show();
}
else if (frm.TextVal == "2" )
{
this.Hide();
Form3 F3 = new Form3();
F3.Show();
}
这样处理不就很完美吗。
看一下代码中是否少分号或者加一个else分支试一下
把窗体变量定义成全局变量,调用更方便一点。这样就不需要new太多实例了。