by TDCNET Visual Basic Page (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
These events are usually ignored or inconsistent amongst programs. For the users benefit, highlighting the current textbox, or tab control will aid in their navigation of your forms. But how to keep all these events consistent? Here is the answer. (Well our answer anyhow... until full-inheritance in VB 5.0)
Add these two procedures to a Module. In each object GotFocus.LostFocus event, place a call to the respective procedure (the CALL qualifier is not neccesary, just the procedure name). This process can also be placed in a VB 4.0 Class.
Public Sub GotFocus()
Set gLastObjectFocus = Screen.ActiveControl
With gLastObjectFocus
If (TypeOf gLastObjectFocus Is TextBox) Or _
(TypeOf gLastObjectFocus Is ComboBox) Or _
(TypeOf gLastObjectFocus Is CSComboBox) Or _
(TypeOf gLastObjectFocus Is sidtEdit) _
Then
.BackColor = &HFF0000 'Dark Blue
ElseIf (TypeOf gLastObjectFocus Is SSTab) Then
.Font.Bold = True
.Font.Italic = True
.ShowFocusRect = True
ElseIf (TypeOf gLastObjectFocus Is CheckBox) Or _
(TypeOf gLastObjectFocus Is CSOptList) Or _
(TypeOf gLastObjectFocus Is OptionButton) Or _
(TypeOf gLastObjectFocus Is SSOption) Then
.ForeColor = &HFF0000 'Dark Blue
End If
End With
End Sub
Public Sub LostFocus()
With gLastObjectFocus
If (TypeOf gLastObjectFocus Is TextBox) Or _
(TypeOf gLastObjectFocus Is ComboBox) Or _
(TypeOf gLastObjectFocus Is CSComboBox) Or _
(TypeOf gLastObjectFocus Is sidtEdit) _
Then
.BackColor = &H00C0C0C0& 'Light Grey
ElseIf (TypeOf gLastObjectFocus Is SSTab) Then
.Font.Bold = False
.Font.Italic = False
.ShowFocusRect = False
ElseIf (TypeOf gLastObjectFocus Is CheckBox) Or _
(TypeOf gLastObjectFocus Is CSOptList) Or _
(TypeOf gLastObjectFocus Is OptionButton) Or _
(TypeOf gLastObjectFocus Is SSOption) Then
.ForeColor = &H0& 'Black
End If
End With
End Sub