重写一文本控件:
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e); if (e.KeyCode == Keys.Down)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged);
}
else if (e.KeyCode == Keys.Up)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged); }
else
{
this.TextChanged += new EventHandler(GridTextBox_TextChanged);
}
} void GridTextBox_TextChanged(object sender, EventArgs e)
{
SetGridDataSource(this.Text);
}
程序意图是 当按上下键的时候 不要激发GridTextBox_TextChanged 事件 而按其它键的时候激发 但是只能移除一次事件,不知道是为什么?也就是当按上下方向键后按下其它键 再按方向键 事件却没有被移除 是怎么回事哦
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e); if (e.KeyCode == Keys.Down)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged);
}
else if (e.KeyCode == Keys.Up)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged); }
else
{
this.TextChanged += new EventHandler(GridTextBox_TextChanged);
}
} void GridTextBox_TextChanged(object sender, EventArgs e)
{
SetGridDataSource(this.Text);
}
程序意图是 当按上下键的时候 不要激发GridTextBox_TextChanged 事件 而按其它键的时候激发 但是只能移除一次事件,不知道是为什么?也就是当按上下方向键后按下其它键 再按方向键 事件却没有被移除 是怎么回事哦
解决方案 »
- 怎么判断一个线程已经绑定一个方法了?
- 江湖救急这次,请各位大侠救我一命,诡异的问题,苦想几天没解决
- 简单问题 :提示不会实现接口成员
- Login 控件的问题
- 我要做个文本比较器,不知道C#里头,有没有这样现成的类可以使用的?
- ##########.net打包出错,错误: 应将“wmp.dll”排除,原因是其源文件“C:\WINDOWS\system32\wmp.dll”受到“Windows 系统文件保护”。?#
- 我在Form中绘制了一个曲线,请问怎么可以将它在Panel控件中显示
- WinFrom多窗体间如何实现for循环切换,在线等啊,急?
- 请教:T-sql 和C#的例子?
- 存储过程
- 無法將'div'項目巢狀化至'tbody'項目中,請問有何方法可以實現?
- 哈希的问题
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e); if (e.KeyCode == Keys.Down&&add)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged);
add=false; }
else if (e.KeyCode == Keys.Up&&add)
{
if (this.gridRow == null || this.gridRow.Length == 0) return;
this.TextChanged -= new EventHandler(GridTextBox_TextChanged);
add=false;
}
else if(!add)
{
this.TextChanged += new EventHandler(GridTextBox_TextChanged);
add=true;
}
} void GridTextBox_TextChanged(object sender, EventArgs e)
{
SetGridDataSource(this.Text);
}
流程 按其它键,事件被触发->按↑↓方向键,事件被移除->再按其它键,事件被绑定->再按↑↓方向键,却发现事件没有被移除.SetGridDataSource(this.Text);继续被执行着.