Autoselect text when tabbing into a textbox

  • Thread starter Thread starter Jonathan Allen
  • Start date Start date
J

Jonathan Allen

In dialog boxes in Windows, the text in TextBox is automatically selected if
you tab into the TextBox , but not when you select the TextBox using the
mouse.

What is the preferred way to support this in VB/C# 2005?
 
Jonathan Allen said:
In dialog boxes in Windows, the text in TextBox is automatically selected
if
you tab into the TextBox , but not when you select the TextBox using the
mouse.

What is the preferred way to support this in VB/C# 2005?

Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles TextBox1.Enter

TextBox1.SelectAll()
End Sub

I believe GotFocus is the other event you should avoid.

"Note The GotFocus and LostFocus events are low-level focus events that
are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically,
the GotFocus and LostFocus events are only used when updating UICues or when
writing custom controls. Instead the Enter and Leave events should be used
for all controls except the Form class, which uses the Activated and
Deactivate events. For more information about the GotFocus and LostFocus
events, see the WM_SETFOCUS and WM_KILLFOCUS topics in the "Keyboard Input
Reference" section of the Platform SDK Documentation in the MSDN library at
http://msdn.microsoft.com/library."

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top