Is there a way to find out if the "TextChanged" event is fired because
- the user is typing into a textbox or
- the programmer called myTextBox.Text = "something"?
只是为了给你一些颜色,我不想在用户将每个字母输入文本框时使用react,所以我使用“已验证”事件来捕捉用户完成的时间,以便我可以使用react。问题是当程序员执行“myTextbox.Text =”something”时我没有办法捕捉到。我知道捕捉更改的唯一方法是使用 TextChanged 但我不想在用户在文本框中输入每个字母。有什么建议吗?
最佳答案
因此在您的“格式化”文本框类中:
public override String Text{
get{return text;}
set
{
//perform validation/formatting
this.text = formattedValue;
}
这应该允许您在程序员更改文本时格式化文本,用户输入验证仍需要在验证事件中处理。
关于c# - 如果用户在文本框中键入内容或以编程方式调用 myTextBox.Text,如何确定是否触发了 "TextChanged"事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9636767/