日期:2014-05-18  浏览次数:20918 次

新手 事件问题 急啊!!!!
用Button_Click事件来关闭应用程序,但在关闭之前要现取消这个两个事件
C# code
  private void textBox1_TextChanged(object sender, EventArgs e)
        {
            TextBox Tb = (TextBox)sender;
            if (textBox1.Text.Length == 0)
            {
                Tb.Tag = false;
                Tb.BackColor = Color.Yellow;
            }
            else
            {
                Tb.Tag = true;
                Tb.BackColor = SystemColors.Window;
            }
        }
         private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            TextBox Tb = (TextBox)sender;
            if (textBox1.Text.Length == 0)
            {
                Tb.Tag = false;
                Tb.BackColor = Color.Yellow;
            }
            else
            {
                Tb.Tag = true;
                Tb.BackColor = SystemColors.Window;
            }
        }

  请问怎样实现?? 各位大虾帮忙啊!!!

------解决方案--------------------
textBox1.Validating-=new EventHandler(textBox1_Validating);
textBox1.TextChanged-=new EventHandler(textBox1_TextChanged);
------解决方案--------------------
C# code

        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.Validating -= new System.ComponentModel.CancelEventHandler(this.textBox1_Validating);
            this.textBox1.TextChanged -= new System.EventHandler(this.textBox1_TextChanged);
            this.Close();
        }

------解决方案--------------------
是在属性设计器里面设置CausesValidation为False不是在Button的Click的代码里面~~~~~

我这边是可以的~~~