Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how can I select all the text in a textbox when I double click?

Using C# how can I select all the text in a textbox when I double click? My text contains spaces "This is a test", when I double click by default only one word is highlighted, how can I highlight all the text?

What I am trying to achieve is a quick way for users to clear the texbox of text, the text exceeds the length of the box so you can't select the end and drag back to delete, you have to click and use the backspace and delete keys to clear the text.

Thanks Alison

like image 204
Alison Craig Avatar asked Nov 11 '10 14:11

Alison Craig


2 Answers

TextBox tb = new TextBox();
tb.SelectAll();

The TextBox has a SelectAll method which you can use. Add it in your double click event handler.

like image 174
Neil Knight Avatar answered Oct 09 '22 04:10

Neil Knight


try something like this. When the MouseDoubleClick-Event is fired...

myTextBox.SelectAll();

Just check the MSDN --> http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase.selectall.aspx

like image 22
cordellcp3 Avatar answered Oct 09 '22 02:10

cordellcp3