PRB: How to Prevent Flicker in the Repaint of a LabelLast reviewed: June 21, 1995Article ID: Q112675 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SYMPTOMSWhen a label control fires a change event, the Caption tends to flicker as it is repainted within the control -- more so when the font size is large.
WORKAROUNDThe flicker can be avoided if a picture control (with its AutoRedraw property set to true) is used instead of the label control. However, note that a picture control uses considerably more resources than a label. If you're going to replace a lot of labels, replace them all with one picture control (and multiple print statements) rather than with multiple picture controls. Otherwise, you'll run out of system resources. The following example demonstrates the use of the picture control to prevent the flicker.
An Alternative to the Picture ControlFlicker in a label can be reduced considerably by only updating it when absolutely necessary. For example, update it at the end by using code similar to this:
Sub Timer1_Timer () Dim TimeStr As String TimeStr = Format$(Now, "h:mm:ss AM/PM") If Label1.Caption <> TimeStr Then Label1.Caption = TimeStr End SubOr by using code similar to this slightly more efficient code:
Sub Timer1_Timer () Static LastSecond As Integer If Seconds(Now) <> LastSecond Then LastSecond = Seconds(Now) Label1.Caption = Format$(Now, "h:mm:ss AM/PM") End If End Sub MORE INFORMATION
Steps to Reproduce Behavior
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |