Just writing values to a so small number of labels is a really fast process. The problems you are experiencing have to do most likely with the VB.NET "problems" while refreshing the contents of GUI controls; the best way to fix this is looking into multithreading, as suggested by FraserOfSmeg.
As far as I think that this is a pretty simplistic GUI with a low number of controls and a not too demanding algorithm (big amount of/long loops is the prime cause of GUI-refreshing problems), you might get an acceptable performance even without relying on multithreading. In your situation, I would do the following:
- A container (the
TableLayoutPanel
you are using or something simpler, like aPanel
) including all the labels at the start. In case of not getting too messy (what does not seem to be the case, with just 42 labels) I would include them in the "design view" (rather than at run time). - A function populating all the labels depending upon the given month.
- A "transition effect" for
the container called every time the user selects a different month.
You can accomplish this quite easily with a
Timer
relocating the container (e.g., when the button is clicked the container's position is set outside the form and then comes back gradually (20 points per 10ms -> made-up numbers) until being back to its original position). - Synchronising the two points above: the values of the labels will start changing when the transition starts; in this way the user will not notice anything (just a nice-appealing transition month to month).
This GUI should deliver the kind of performance you are after. If not, you should improve its performance by relying on additional means (e.g., the proposed multi-threading).
SAMPLE CODE TO ILLUSTRATE POINT 3
Add a panel (Panel1
), a button (Button1
) and a timer (Timer1
) to a new form and the code below.
Public Class Form1
Dim curX, origX, timerInterval, XIncrease As Integer
Dim moving As Boolean
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If (curX >= origX) Then
If (moving) Then
curX = Panel1.Location.X
moving = False
Timer1.Stop()
Else
curX = 0 'getting it out of the screen
moving = True
End If
Else
curX = curX + XIncrease
End If
Panel1.Location = New Point(curX, Panel1.Location.Y)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
XIncrease = 100
timerInterval = 100
Panel1.BackColor = Color.Maroon
origX = Panel1.Location.X
curX = origX
With Timer1
.Enabled = False
.Interval = timerInterval
End With
End Sub
End Class
This is very simplistic, but shows the idea clearly: when you click the button the panel moves in X; by affecting the timerInterval
and XIncrease
values you can get a nice-looking transition (there are lots of options, bear in mind that if you set curX
to minus the width of the panel, rather than to zero, it goes completely outside the form).