日期:2014-05-19  浏览次数:20883 次

为什么会这样?
private   void   button1_Click(object   sender,   EventArgs   e)
                {
                        String   this_url,   this_timer;
                        this_url   =   textBox1.Text;
                        this_timer   =   textBox2.Text;
                        if   (this_url   ==   " ")  
                        {
                                MessageBox.Show( "请输入回调网址! ");
                                textBox1.Focus();
                        }
                        if   (this_timer   ==   " ")
                        {
                                MessageBox.Show( "请输入刷新时间! ");
                                textBox2.Focus();
                        }
                  }
---
为什么textBox1.Text为空时,有提示信息,却textBox2.Text为空时就没有了?

------解决方案--------------------
不要用 " " 用string.empty
试下这个
if (this_url == " ")
{
MessageBox.Show( "请输入回调网址! ");
textBox1.Focus();
}
else
{
if (this_timer == " ")
{
MessageBox.Show( "请输入刷新时间! ");
textBox2.Focus();
}
}
第二个没有提示可能是你textBox2控件的Text有空白
你可以用textBox2.Text.trim()
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim() == " ")
{
MessageBox.Show( "请输入回调网址! ");
textBox1.Focus();
}
if (textBox2.Text.Trim() == " ")
{
MessageBox.Show( "请输入刷新时间! ");
textBox2.Focus();
}
}
------解决方案--------------------
代码没问题啊?LZ可能在text2里有空格什么在的吧,你改成这样试一下应该没问题的
this_url = textBox1.Text.Trim();

this_timer = textBox2.Text.Trim();
------解决方案--------------------
if (this_url == " ") {
MessageBox.Show( "请输入回调网址! ");
textBox1.Focus();
}
else if(this_timer == " "){
MessageBox.Show( "请输入刷新时间! ");
textBox2.Focus();