I have a TextBox
and I want all the text inside of it to be highlighted when the user clicks on it (so that they can replace it easily). I have the following event handler linked up the the TextBox
:
private void TextBox_Enter(object sender, EventArgs e) {
SelectAll();
}
When I click on the TextBox
, the text is only selected for a fraction of a second (sometime it's so fast I can't see it at all) and then it goes back to being a cursor. Does anyone know how to fix this or if there are any relatively simple workarounds?
I tried the same thing with the TextBox.MouseClick
event (and it highlighted the text), but because it was the MouseClick
event the text was highlighted every time I clicked the TextBox
(even when the TextBox
already had focus).
I have also tried SelectionStart = 0; SelectionLength = Text.Length
, but the same thing happens. This leads me be believe the issue has something to do with the event.
I also tried the TextBox.GotFocus
event and had the exact same problem.
I am doing this in a Windows Form application.