I’ve got a Form with some labels on it.
From time to time the program changes the text on the labels with
label1.Text = "some message"
I want to create a function that is executed every time the label text is assigned and implemented an event handler like this:
this.label1.TextChanged += new System.EventHandler(this.label1_TextChanged);
[...]
private void label1_TextChanged(object sender, EventArgs e) {
// do some stuff
}
This works fine as long as the text is really changed. But if the text is set to the same value it already has, the event doesn’t execute. Is there an easy way to hook a function into the text assignment without changing every occurence of label1.Text = ... to a custom function call?
The Control’s Text property is virtual so you can create your own label control and add custom functionality there, such as raising an event when the property’s setter is called even if it doesn’t result in changed text.