Previous | Index | Next 

[HOWTO] Speed up execution by removing unnecessary Refresh methods

Assigning a property of a VB6 control via code typically doesn’t update the control, until the application enters the “idle” state and all UI items are updated automatically. VB6 developers are aware of this behavior and use to add calls to the control’s Refresh method to force the update when the property is assigned inside a loop. This technique is often necessary, for example, to display a running percentage in a Label control.

Conversely, most .NET controls – and therefore, most controls in the CodeArchitects.VBLibrary – are updated automatically as soon as one of their properties is assigned a different value. For this reason, calls to the Refresh methods are unnecessary and can be safely removed after the migration. You can remark out calls to Refresh method by means of a ParseMode pragma:

        Dim i As Integer
        For i = 0 To 10000
            Label1.Caption = i & "%"
            '##ParseMode Remarks, 1
            ' ...

In addition to refreshes caused by unnecessary Refresh methods, keep in mind that VB.NET controls can receive a WM_PAINT even if you change a visual property of their container, for example the Caption property of the parent form.


Previous | Index | Next