TextBox text selected on entry

TextBox text selected on entry

Post by R0wtRFNIU » Sat, 27 Sep 2008 22:30:04


How can I control whether the text in a Textbox is automatically selected
(highlighted) upon entry into the Textbox? Sometimes when tabbing into a
Textbox, the text is automatically highlighted, and sometimes it is not. I
need to be able to control this. I want be able ot set it so that the text
is Never automatically highlighted upon entry into the Textbox.

VS-2005, Windows Forms

Thanks for any information.

-Gary
 
 
 

TextBox text selected on entry

Post by Eddi » Sat, 27 Sep 2008 23:12:15


IIRC, each control remembers its selection settings from the last time
it had focus.


Add a handler for the Enter or GotFocus event to set the SelectionStart
and SelectionLength properties.

--
Eddie XXXX@XXXXX.COM

 
 
 

TextBox text selected on entry

Post by kimiraikko » Thu, 02 Oct 2008 17:03:50


> is Never automatically highlighted upon entry into the Textbox. ? >

Gary,
Try this:

Private Sub TextBox1_GotFocus(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.GotFocus
TextBox1.Select(0, TextBox1.Text.Length)
End Sub

It must select(highlight) the entire text in textbox when it gets
focus. Plus, pressing TAB key between controls should be enough to
highlight text in textbox.

Hope this helps,

Onur G鼁el
 
 
 

TextBox text selected on entry

Post by Jeff Johns » Thu, 09 Oct 2008 05:43:49


Argh. And what happens when you click in the text box with the mouse?
Everything gets selected. This is NOT standard Windows behavior. If you go
this route you should employ some simple tracking of whether the mouse or
the keyboard was used to enter the text box.
 
 
 

TextBox text selected on entry

Post by Jack Jacks » Thu, 09 Oct 2008 07:25:15

On Tue, 7 Oct 2008 16:43:49 -0400, "Jeff Johnson" < XXXX@XXXXX.COM >





Microsoft recommends using the Enter event rather than GotFocus for
things like this, but I'm not sure it really matters.

In my experience, clicking in the control with code like above in the
Enter event does not select the text. The MouseClick event occurs
after the Enter event which then undoes the SelectAll() that I do in
Enter.

It isn't clear to me what the behavior should be when moving focus to
the textbox via a mouse click. I think it depends on what the user
intends to do to the textbox. Sometimes selecting all of the text is
probably what the user wants.
 
 
 

TextBox text selected on entry

Post by Jeff Johns » Fri, 10 Oct 2008 22:44:51


Standard dialog box behavior is to select all text when tabbing, at least
for single-line text boxes. For multi-line text boxes I think it would be
user-friendly to remember the last position of the caret and restore that.

Or you could use the example that Access has put forth for a long time (at
least since I started working with it in 2.0): let the user choose whether
to select all, put the caret at the beginning, or at the end.