On CNET: High-fashion high-definition TVs

Displaying control-specific instructions in VB6 with GotFocus

Tags: Microsoft development tools, Peter Aitken, GotFocus, Microsoft Visual Basic 6.0, Visual Basic Tips Newsletter

  • Save
  • Print
  • 0

Takeaway: The GotFocus event for a control fires in VB6 when the control receives the focus through user action or through the SetFocus method. See how you can use GotFocus to display information or instructions to the user.

The GotFocus event for a control fires in VB6 when the control receives the focus through user action or through the SetFocus method being executed in the code. You can use GotFocus to display information or instructions to the user, perhaps in a Status Bar control.

For example, suppose there is a TextBox where the user is supposed to enter a phone number in a specific format. You could inform the user of the format as follows:



Private Sub txtPhoneNumber_GotFocus()

Status1.Text = "Please enter the phone number in this format: xxx-xxx-xxxx"

End Sub

You can also use a control's LostFocus event to clear the message when the focus moves away from the control to prevent possible confusion.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

Miss a column?

Check out the Visual Basic Archive, and catch up on the most recent editions of Peter Aitken's article.

  • Save
  • Print
  • 0

Print/View all Posts Comments on this article

Good as far as it goesmaclean@...  | 11/04/05
Be awareTony Hopkinson  | 11/04/05
Why GotFocus doesn't always work...illilli  | 11/07/05
Got focus usually works wellTony Hopkinson  | 11/07/05
OnEnter?george.jeffrey@...  | 01/13/06
Workaround for GotFocus Problemannedecker@...  | 01/23/06

What do you think?

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here