Windows Forms: SelectionChanged event for TextBox

2019-01-19 00:42发布

问题:

How do I get notified of a selection change in a text box in .NET 2.0? I was unable to find a SelectionChanged event or an OnSelectionChanged method. What is the best workaround for this (without having to PInvoke, of course)?

回答1:

You could use a RichTextBox and set Multiline to false. It has a OnSelectionChanged.



回答2:

Well, I guess this may help! You will need to use RichTextBox still.



回答3:

You can use TextBox also.

Write a funktion GetMyPosition() and put in the events

  • TextChanged()
  • MouseClick()
  • KeyUp() (In KeyDown() the position isn't changed)

When you want to notify the highliting of a text, you also have to use - MouseHover()