how to highlight/select text in a wpf textbox with

2019-02-11 21:55发布

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!

2条回答
霸刀☆藐视天下
2楼-- · 2019-02-11 22:39

You can use the following code to achieve your purpose:

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

Hope this helps. Here's the source.

查看更多
3楼-- · 2019-02-11 22:50

Another alternative:

textBoxName.SelectAll();
查看更多
登录 后发表回答