- Home /
Select all text in a GUI.TextField?
Hi, I would like my menu to select all text in a TextField when the user clicks on it.
I have found this related question so far, but the solution suggested there (having something else selected first by GUI.FocusControl) doesn't achieve that result.
Is there any method to select the whole text? Anything?
Answer by Paulius-Liekis · Oct 10, 2012 at 10:25 AM
Try using TextEditor class:
idString = GUI.TextField(new Rect (0, 0, 100, 20), idString);
textEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
Then textEditor gives you cursor position and similar things. Maybe it has selection too. It's undocumented class, IIRC, so use with caution.
Your answer
Follow this Question
Related Questions
Backspace in limited length textfield causes ArgumentOutOfRangeException 1 Answer
GUILayout Textfield not editable just static 1 Answer
Android Textfield locks out input until esc 2 Answers
Text.Field erratically updating 0 Answers
Unity Shutdown 1 Answer