首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

为什么会这样?解决思路

2012-02-27 
为什么会这样?privatevoidbutton1_Click(objectsender,EventArgse){Stringthis_url,this_timerthis_urlt

为什么会这样?
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();


}else{
//do something here
}

检查一下你的VS.net或.net framework环境配置这些正确吗?

热点排行