Reducing Control Flicker

These properties are usually ones that cause the control to re-paint, like Enabled, Visible, Caption and Text. The flicker can be easily reduced by not setting a property when it is already set. For instance, if the Enabled property is set to True why set it to True again?

Enable/Disable Routine

Use this to enable or disable a control.

Sub SetEnabled (ctrlIn as Control, bSetting as Integer)
     If ctrlIn.Enabled <> bSetting Then
           ctrlIn.Enabled = bSetting
     End If
End Sub

Caption Routine

Use this to change a Caption property.

Sub SetLabel (ctrlIn as Control, sNewText as String)
     If ctrlIn.Caption <> sNewText Then
           ctrlIn.Caption = sNewText
     End If
End Sub

You can make as many of these types of routines as you like. Any property that affects a controls appearance, such as colors, fonts and text, would be a good prospect.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter