Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to highlight/select text in a wpf textbox without focus?

Tags:

I want to highlight selected text in a wpf textbox while the textbox is not focused. In my application, my textbox never gets focus, and every key input is done manually.

I was wondering if there is a way to highlight the selected text when the textbox is not focused?

Any help would be appreciated!

like image 214
user1340852 Avatar asked Aug 23 '12 15:08

user1340852


People also ask

How do I highlight a TextBox in WPF?

You can use the following code to achieve your purpose: textBoxToHighlight. Focus(); textBoxToHighlight. Select(0, textBoxToHighlight.

How do you make a TextBox non editable in WPF?

To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.

What is TextBox in WPF?

The TextBox class enables you to display or edit unformatted text. A common use of a TextBox is editing unformatted text in a form. For example, a form asking for the user's name, phone number, etc would use TextBox controls for text input.


1 Answers

You can use the following code to achieve your purpose:

textBoxToHighlight.Focus(); textBoxToHighlight.Select(0, textBoxToHighlight.Text.Length); 

Hope this helps.

like image 115
pdvries Avatar answered Sep 18 '22 13:09

pdvries