How do I monitor the TextBox.SelectionStart property of winform for changes?


I have a multiline text box, and I'd like to display the user's current line number and column number in a label below the text box. It looks like I can get the line number and column number using the SelectionStart property, GetLineFromCharIndex method, and GetFirstCharIndexOfCurrentLine method. However, I can't see any event that gets fired every time the selection changes in the text box.

The best I can see is to monitor the KeyPress and MouseDown events and check the SelectionStart property after each event. I suppose I could use a timer to watch for changes, but that feels weird.

Have I missed something?

To be robust, you're probably going to have to add a timer, and just check it regularly; from here, the control doesn't post suitable win32 messages (EN_SELCHANGE) to do this as an event.