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
TextBox tb = new TextBox();
tb.SelectAll();
The TextBox has a SelectAll
method which you can use. Add it in your double click event handler.
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
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