Need help with AddHandler

Currently I have a TextField with an EventHandler of Text Change. I really would like to change the TextField to a Label. I can see that a Label doesn’t have a TextChange event, but I wondered if I could create one with AddHandler. (If so, I’m not sure how.)

Alternatively, the reason I want to do this is because it is the program that changes the text in the TextField (soon to be Label, I hope). Although I have set the TextField to be Read Only, the Text Insertion bar (?) is still flashing in the Field. So alternatively, is there a way to disable the text insertion bar in a Text Field?

If it is only the program that can change the text then you should add a method to set the text and do whatever else and call that method rather than changing the text directly.

However if you don’t trust the programmer to abide by that rule you can:

Add a container control to your project.
Set its width & height to 100 x 22
drag a label onto the container & lock the label to the 4 sides of the container
make the label private
Add an event definition TextChanged
Add a computed property that is public called caption (or something unique)
In the get return the label text
In the set apply the text to the label & raise the TextChanged event

Use this container as your label.

Unless I missed something, .TEXT isnt something you can add a handler for.
And I dont seem to be able to mask a .Text property with a method or computed property of the same name in the subclass.

If the program sets the text and you want to do something when the text is changed, here are some options

a/Direct all calls to set the text through a method where you pass the name of the label and the new text. The method does something and sets the text

b/subclass a label and add a Caption computed property and a TextChanged event
In that, note that the text is changing, raise the TextChanged event, and change the text.
Change the program to use label.caption instead of label.text

c/subclass a label and add a SetText method and a TextChanged event.
In that, note that the text is changing, raise the TextChanged event, and change the text.
In the program, change label.text = to label.SetText ()

@Wayne Golding Thanks Wayne.

I have to trust the programmer, because that’s me! I guess I never thought of a Method because TextChange was so easy to implement in the first place, but now I want to change it to a Label, the story is different.