I have multiple text boxes in my windows form whose text I want to become selected when they are clicked on by the user. I am trying to find a way to make only the first click in a box select text when the user makes consecutive clicks in the box. I would like to have subsequent clicks in the same box position a text cursor box rather than endlessly select the text, which is what is happening now.
I have tried calling focused.Select() inside an if statement that only runs if no text is already selected like shown below. The problem with that is that right after a user clicks on selected text briefly "un-selects" then Highlight_OnClick runs and the text is again selected.
private void HighlightWhenFocused(object sender, EventArgs e)
{
if (sender is TextBox)
{
TextBox focused = sender as TextBox;
focused.Select(0, focused.Text.Length);
//if (focused.SelectionLength == 0 { focused.Select(0, focused.Text.Length); }
// does not work either
}
}
My code above always selects the text but the problem is that even once the user has clicked on a text box that is already selected, subsequent clicks only re-select the text.