Agnel Kurian
Agnel Kurian

Reputation: 59516

Windows Forms: SelectionChanged event for TextBox class

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)?

Upvotes: 13

Views: 9018

Answers (4)

ck1mark
ck1mark

Reputation: 1

“selection change in a text box” If this means SelectedText changed than I needed to do this with a combo box. How: Created a MouseUp event which requires if selected text length > 0

Upvotes: -1

marsh-wiggle
marsh-wiggle

Reputation: 2813

You can use TextBox also.

Write a function GetMyPosition() and put in the events

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

When you want to notify the highlighting of a text, you also have to use

  • MouseHover()

Upvotes: 5

Ahmed
Ahmed

Reputation: 11423

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

Upvotes: 1

Hamid
Hamid

Reputation: 156

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

Upvotes: 4

Related Questions