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为空时就没有了?

解决方案 »

  1.   

    不要用 "" 用string.empty
    试下这个
                if (this_url == "") 
                {
                    MessageBox.Show("请输入回调网址!");
                    textBox1.Focus();
                }
                else
                {
                    if (this_timer == "")
                    {
                        MessageBox.Show("请输入刷新时间!");
                        textBox2.Focus();
                    }
                }
    第二个没有提示可能是你textBox2控件的Text有空白
    你可以用textBox2.Text.trim()
      

  2.   

    private void button1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text.Trim() == "") 
                {
                    MessageBox.Show("请输入回调网址!");
                    textBox1.Focus();
                }
                if (textBox2.Text.Trim() == "")
                {
                    MessageBox.Show("请输入刷新时间!");
                    textBox2.Focus();
                }
             }
      

  3.   

    代码没问题啊?LZ可能在text2里有空格什么在的吧,你改成这样试一下应该没问题的
    this_url = textBox1.Text.Trim(); this_timer = textBox2.Text.Trim();
      

  4.   

    this_url = textBox1.Text.Trim();
      this_timer = textBox2.Text.Trim();
    用这个试试,不过,lz的代码,在我机器上是正确的,两个都会有提示信息
      

  5.   

    代码没什么问题呀...
    lz在好好查一下.查一下this_timer.length是多少
      

  6.   

    奇怪了,在我本机还是有这个问题,text.Box2有内容都正常,一旦没有内容,就没有反应,甚至连程序关闭的按钮也不能用,还有一个问题就是用message.show(this_timer.length),不能运行,提示出错
      

  7.   

    if (this_url == "") {
                    MessageBox.Show("请输入回调网址!");
                    textBox1.Focus();
     }
    else if(this_timer == ""){
                     MessageBox.Show("请输入刷新时间!");
                     textBox2.Focus();
    }else{
    //do something here
    }检查一下你的VS.net或.net framework环境配置这些正确吗?