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

前端 未结 3 1768
悲哀的现实
悲哀的现实 2020-12-31 00:36

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.

相关标签:
3条回答
  • 2020-12-31 01:11

    You can use the following code to achieve your purpose:

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

    Hope this helps.

    0 讨论(0)
  • 2020-12-31 01:22

    Another alternative:

    textBoxName.SelectAll();
    
    0 讨论(0)
  • 2020-12-31 01:23

    I really like this type of selection:

    textbox.Focus();
    textbox.SelectionStart = 0;
    textbox.SelectionLength = textbox.Text.Lenght;
    
    0 讨论(0)
提交回复
热议问题