Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting word from textbox

Tags:

c#

textbox

I'm looking for a method to get the value for a selected word from textbox.

For example:

I have textbox.Text =" How are you";

when I select "are" I should get message with selected word MessegeBox.Show(selectedWord);

like image 315
Eyla Avatar asked Aug 12 '26 23:08

Eyla


2 Answers

The Windows Forms TextBox control has a SelectedText property which will return the selected portion of the TextBox's value.

http://msdn.microsoft.com/en-us/library/aa288415%28VS.71%29.aspx

like image 122
Nathan Taylor Avatar answered Aug 15 '26 08:08

Nathan Taylor


Windows Forms TextBox doesn't have a SelectionChanged event, although the RichTextBox control does. You could use a variety of hacks such as a timer, handling mouse up and key up events to trigger your selection change logic. Then use the SelectedText as others have suggested.

like image 42
Josh Avatar answered Aug 15 '26 09:08

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!