- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在制作一个 C# Windows 窗体来检查所有条目,当所有条目都有效时,将出现一个消息框,但我需要帮助确保所有条目都有效并显示一个消息框。做这一切可能更容易,但不妨学习如何做这一切。这是我目前所拥有的。
private void btn_submit_Click(object sender, EventArgs e)
{
string name = txt_name.Text;
string email = txt_email.Text;
string address = txt_address.Text;
string course = txt_course.Text;
string phone = txt_phone.Text;
if (name.Length < 8)
{
txt_name.Text = "Invalid Name";
txt_name.ForeColor = Color.Red;
}
else
{
txt_name.ForeColor = Color.Green;
}
if (email.Contains('@'))
{
if (email.Contains(".com") || email.Contains(".COM"))
{
txt_email.ForeColor = Color.Green;
}
else
{
txt_email.Text = "invalid Email";
txt_email.ForeColor = Color.Red;
}
}
else
{
txt_email.Text = "invalid Email";
txt_email.ForeColor = Color.Red;
}
if (address.Length < 12)
{
txt_address.Text = "invalid Address";
txt_address.ForeColor = Color.Red;
}
else
{
txt_address.ForeColor = Color.Green;
}
if (course.Contains("Games Design") || course.Contains("Electronics") || course.Contains("Mobile Communications") || course.Contains("GAMES DESIGN") || course.Contains("ELECTRONICS") || course.Contains("MOBILE COMMUNICATIONS"))
{
txt_course.ForeColor = Color.Green;
}
else
{
txt_course.Text = "invalid Course";
txt_course.ForeColor = Color.Red;
}
if (phone.Length < 8)
{
txt_phone.Text = "invalid Phone Number";
txt_phone.ForeColor = Color.Red;
}
else
{
txt_phone.ForeColor = Color.Green;
}
}
最佳答案
您可以在验证失败的任何地方添加一个 bool 值并将其设置为 false。
private void btn_submit_Click(object sender, EventArgs e)
{
string name = txt_name.Text;
string email = txt_email.Text;
string address = txt_address.Text;
string course = txt_course.Text;
string phone = txt_phone.Text;
bool formIsValid = true;
if (name.Length < 8)
{
txt_name.Text = "Invalid Name";
txt_name.ForeColor = Color.Red;
formIsValid = false;
}
else
{
txt_name.ForeColor = Color.Green;
}
if (email.Contains('@'))
{
if (email.Contains(".com") || email.Contains(".COM"))
{
txt_email.ForeColor = Color.Green;
}
else
{
txt_email.Text = "invalid Email";
txt_email.ForeColor = Color.Red;
formIsValid = false;
}
}
else
{
txt_email.Text = "invalid Email";
txt_email.ForeColor = Color.Red;
formIsValid = false;
}
if (address.Length < 12)
{
txt_address.Text = "invalid Address";
txt_address.ForeColor = Color.Red;
formIsValid = false;
}
else
{
txt_address.ForeColor = Color.Green;
}
if (course.Contains("Games Design") || course.Contains("Electronics") || course.Contains("Mobile Communications") || course.Contains("GAMES DESIGN") || course.Contains("ELECTRONICS") || course.Contains("MOBILE COMMUNICATIONS"))
{
txt_course.ForeColor = Color.Green;
}
else
{
txt_course.Text = "invalid Course";
txt_course.ForeColor = Color.Red;
formIsValid = false;
}
if (phone.Length < 8)
{
txt_phone.Text = "invalid Phone Number";
txt_phone.ForeColor = Color.Red;
formIsValid = false;
}
else
{
txt_phone.ForeColor = Color.Green;
}
if (formIsValid)
{
//submit the form
}
else
{
MessageBox.Show("Your error message here");
}
}
关于C# windows 窗体检查所有条目然后显示消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493618/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!