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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s