Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleHighlight the TextBox that has focus by changing its BackColor
DescriptionThis example shows how to highlight the TextBox that has focus by changing its BackColor in Visual Basic 6.
Keywordshighlight, focus, GotFocus, LostFocus, TextBox
CategoriesControls, Miscellany
 
Subroutines HighlightControl and UnHighlightControl set a control's BackColor property to highlighted and non-highlighted values respectively.
 
Private m_FocusControl As Control
' Highlight the newly selected control.
Private Sub HighlightControl(ByVal ctl As Control)
    ctl.BackColor = RGB(&HC0, &HFF, &HFF)
End Sub

' Unhighlight the newly selected control.
Private Sub UnHighlightControl(ByVal ctl As Control)
    ctl.BackColor = vbWhite
End Sub
 
The program calls HighlightControl in each TextBox's GotFocus event handler. It calls UnHighlightControl in each TextBox's LostFocus event handler.
 
Private Sub txtCity_GotFocus()
    HighlightControl txtCity
End Sub

Private Sub txtCity_LostFocus()
    UnHighlightControl txtCity
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated