为什么声明不起作用 [英] Why if statement not working
本文介绍了为什么声明不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么每次第一个条件执行以及我使用什么代码将一个表单移动到另一个表单b'coz没有显示属性打开如果我在else块中执行此操作(form2.show)。
why every time first condition execute and what code i use for move one one form to another form b'coz no show property open if i do this(form2.show)inside of else block.
private void cmdgo_Click(object sender, EventArgs e)
{
if(txtuser.Text != null && txtpass.Text != null)
{
MessageBox.Show("Username and Password should not blank", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("Welcome");
}
}
在此先感谢.....
Thanks In Advance.....
推荐答案
尝试这样做:
Try to do this:
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
if((txtuser.Text == string.empty) && (txtpass.Text == string.empty))
{
MessageBox.Show("Username and Password should not blank", "input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("Welcome");
}
-KR
-KR
//您正在将txtuser.Text与null进行比较,以便不能为null所以它去其他地方
// .Trim()将删除起始和结束空格
//这样如果有人进入空格,它将删除它并检查
private void cmdgo_Click(object sender,EventArgs e)
{
if(txtuser.Text。 Trim () == && txtpass.Text。修剪() == )
{
MessageBox.Show(用户名和密码不应为空白,输入错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
MessageBox.Show(欢迎);
}
}
//you are comparing txtuser.Text with null so that can't be null so its going to else
// .Trim() will remove starting and ending spaces
// so that if someone entered spaces it will remove it and check
private void cmdgo_Click(object sender, EventArgs e)
{
if(txtuser.Text.Trim() == "" && txtpass.Text.Trim() == "")
{
MessageBox.Show("Username and Password should not blank" , "input error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("Welcome");
}
}
这篇关于为什么声明不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文