Auto highlight text in a textbox control

Kevin picture Kevin · Jan 28, 2010 · Viewed 129.9k times · Source

How do you auto highlight text in a textbox control when the control gains focus.

Answer

Reed Copsey picture Reed Copsey · Jan 28, 2010

In Windows Forms and WPF:

textbox.SelectionStart = 0;
textbox.SelectionLength = textbox.Text.Length;