读书人

新手 事件有关问题 急

发布时间: 2012-01-07 21:41:55 作者: rapoo

新手 事件问题 急啊!!!!
用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的代码里面~~~~~

我这边是可以的~~~

读书人网 >C#

热点推荐