Lost Focus / Got Focus Event--text box validation
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)
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
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 Upload
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine