I am looking for help on how to speed up VB.NET (or C#) screen refresh speed. Specifically I need to update many controls and then refresh them on the screen all at once.
I am in charge of writing a .NET interface for an older legacy program. Because this needs to run on slow legacy machines I did a performance test and discovered the screen refresh speeds of VB6 is faster then .NET.

In VB6 there is barely a flicker as controls change across the entire form all at once. In VB.NET you can see controls change moving across the form like a wave. I must be doing something wrong...
To do a head to head comparison I put together equivalent VB6 and VB.NET programs, each with a maximized form and 48 labels. Clicking on any label changes the background color of all the labels on the form. To really see the problem it is best to try the following code on a slower machine (1GHz etc.)
In VB6 create a project MyProject and add a form MyForm with the following properties
CODE
Caption = "Screen Refresh test VB6"
BackColor = Black
WindowState = Maximized
On that form add a label MyLabel with the following properties:
CODE
Index = 0
Caption = "Hello World"
BackColor = Cyan
In the form add the following code:
CODE
Option Explicit
Const ROWS As Integer = 8
Const COLS As Integer = 6
Const PAD As Integer = 75 ' 5 pixels at 15 twips per pixel
Private colors(0 To 2) As Long
Private color As Integer
Private Sub Form_Load()
Dim index As Integer
colors(0) = vbCyan
colors(1) = vbYellow
colors(2) = vbGreen
For index = 1 To ROWS * COLS - 1
Call Load(MyLabel(index))
MyLabel(index).Caption = MyLabel(index).Caption & " " & CStr(index)
MyLabel(index).Visible = True
Next index
MyLabel(0).Caption = MyLabel(0).Caption & " 0"
End Sub
Private Sub Form_Resize()
Dim width As Single
Dim height As Single
Dim row As Integer
Dim col As Integer
Dim index As Integer
width = (Me.width - 60 - PAD * (COLS + 1)) \ COLS
height = (Me.height - 450 - PAD * (ROWS + 1)) \ ROWS
For col = 0 To COLS - 1
For row = 0 To ROWS - 1
index = col * ROWS + row
Call MyLabel(index).Move(PAD + col * (width + PAD), PAD + row * (height + PAD), width, height)
Next row
Next col
End Sub
Private Sub MyLabel_Click(index As Integer)
color = (color + 1) Mod 3
For index = 0 To ROWS * COLS - 1
MyLabel(index).BackColor = colors(color)
Next index
End Sub
The VB.NET program is virtually identical. Just create a windows project and past in the following code. This code defines a form and is self sufficient. It does not need the auto generated form code.
CODE
Public Class MyForm
Inherits System.Windows.Forms.Form
Private Const _ROWS As Integer = 8
Private Const _COLS As Integer = 6
Private Const _PAD As Integer = 5
Private _myLabel(_ROWS * _COLS - 1) As System.Windows.Forms.Label
Private _colors() As System.Drawing.Color = {Color.Cyan, Color.Magenta, Color.Yellow}
Private _color As Integer
Public Sub New()
Me.SuspendLayout()
For index As Integer = 0 To _ROWS * _COLS - 1
Me._myLabel(index) = New System.Windows.Forms.Label
Me._myLabel(index).BackColor = System.Drawing.Color.Cyan
Me._myLabel(index).Name = "MyLabel" & CStr(index)
Me._myLabel(index).TabIndex = index
Me._myLabel(index).Text = "Hello World " & CStr(index)
Me._myLabel(index).TextAlign = System.Drawing.ContentAlignment.MiddleCenter
AddHandler Me._myLabel(index).Click, AddressOf MyLabel_Click
Me.Controls.Add(Me._myLabel(index))
Next
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.StartPosition = FormStartPosition.CenterScreen
Me.WindowState = FormWindowState.Maximized
Me.BackColor = Color.Black
Me.Name = "MyForm"
Me.Text = "Screen Refresh Test VB.NET"
Me.ResumeLayout(False)
End Sub
Private Sub MyForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Dim resize As System.Drawing.Size = _
New System.Drawing.Size _
( _
(Me.ClientRectangle.Width - (_PAD * _COLS + 1)) \ _COLS, _
(Me.ClientRectangle.Height - (_PAD * _ROWS + 1)) \ _ROWS _
)
Me.SuspendLayout()
For col As Integer = 0 To _COLS - 1
For row As Integer = 0 To _ROWS - 1
With Me._myLabel(col * _ROWS + row)
.Size = resize
.Location = New System.Drawing.Point(_PAD + col * (.Width + _PAD), _PAD + row * (.Height + _PAD))
End With
Next
Next
Me.ResumeLayout()
End Sub
Private Sub MyLabel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
_color = (_color + 1) Mod _colors.Length
For index As Integer = 0 To _ROWS * _COLS - 1
Me._myLabel(index).BackColor = _colors(_color)
Next
End Sub
End Class