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!
You can use the following code to achieve your purpose: textBoxToHighlight. Focus(); textBoxToHighlight. Select(0, textBoxToHighlight.
To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.
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.
You can use the following code to achieve your purpose:
textBoxToHighlight.Focus(); textBoxToHighlight.Select(0, textBoxToHighlight.Text.Length);
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With