111,129
社区成员
发帖
与我相关
我的任务
分享
public RemoveTextChanged()
{
InitializeComponent();
textBox1.Text = "abc";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.TextChanged -= textBox1_TextChanged; //暂时删除事件
//随便你怎么改Text都不会再触发TextChanged事件
textBox1.Text = "abc";
textBox1.TextChanged += textBox1_TextChanged; //再重新注册
}
public partial class RemoveTextChanged : Form
{
public RemoveTextChanged()
{
InitializeComponent();
textBox1.TextChanged -= textBox1_TextChanged; //暂时删除事件
textBox1.Text = "abc";
textBox1.TextChanged += textBox1_TextChanged; //再重新注册
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
MessageBox.Show("我是事件触发的");
}
}
/*
*代码如下可处理:
*/
private bool isIDo = false;
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (isIDo)
{
isIDo = false;
return;
}
if (textBox1.Text == "123")
{
textBox1.Text = "456";
isIDo = true;
}
}
public void ModifyTextBoxWithoutEvent(TextBox txt,String value)
{
//删除OnTextChanged事件
txt.Text = value;
//再加上事件
}

this.Invoke(Text_Change);
private void Text_Change()
{
...
}