我是初学C#的学习者。如果我有2个文本框,我可以验证1个if
语句中的2个文本框吗?多文本框验证
例如:
{
string emptytextbox
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.text == "")
{
//if textbox2 is empty, then messagebox will show
emptytextbox = textBox2.text;
mbox(emptytextbox + " must be filled");
//messagebox will show "textBox2 must be filled"
//but if textbox1&2 has ben filled, but textbox3 empty,then messagebox will show "textbox3 must be filled"
}
}
我能做到这一点?
做到这要看你的需求。如果你想在两个文本框都为空时执行一些动作,那么你可以有一个if语句,否则你需要多个嵌套或单独的if条件。 – Hassan
有更好的方法来实现这个功能。你在使用Windows窗体应用程序吗? – Hassan