I have a simple TextBox that is empty in the beginning. I have a simple event, _TextChanged, to know when the user changed anything in that TextBox. However, the event fires if I do anything with it myself from within code. Like setting textbox.Text = "Test"; or similar.
private void textNazwa_TextChanged(object sender, EventArgs e) {
changesToClient = true;
}
How do I make the event only fire on user interaction and not code changes?
The event itself does not make a distinction between text entered via user input and text changed via code. You’ll have to set a flag yourself that tells your code to ignore the event. For example,
Then use this to set the text instead of just calling
Text = "...";:Judging by your comment to another answer, it sounds like you have quite a number of textboxes. In that case, you could modify the function in this way:
Then call it like this:
This would accomplish the same thing as just doing
textNazwa.Text = "foo", but will set the flag letting your event handler know to ignore the event.