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

新手 事件有关问题 急

2012-01-07 
新手 事件问题急啊!!!!用Button_Click事件来关闭应用程序,但在关闭之前要现取消这个两个事件C# codeprivat

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

我这边是可以的~~~

热点排行