mandelbrot
Centurion
Hi All,
I'm having a rather annoying problem at the moment with a form that is made up of a panel filled with labels that basically make up a three month calendar. When I change the visible property of the controls I seem to be suffering some kind of memory leak.
I've already had memory leaks previously (which I managed to fix), but this one seems to be beyond me...
The program falls out at the line indicated. Can anyone spot anything directly obvious that may affect memory?
monthCtl is simply an array that contains a set of references to objects on the form (labels). The yearSeps are two picture boxes that are turned on and off between years.
Thanks in advance,
Paul.
I'm having a rather annoying problem at the moment with a form that is made up of a panel filled with labels that basically make up a three month calendar. When I change the visible property of the controls I seem to be suffering some kind of memory leak.
I've already had memory leaks previously (which I managed to fix), but this one seems to be beyond me...
Visual Basic:
Private Sub RefreshCalendar(ByVal paramDate As Date)
'Standard definitions...
Dim dayCtl As Control
Dim loopCounter As Integer
Dim innerLoop As Integer
Dim tempDate As Date
Dim dayNum As Integer
Dim calNum As Integer
Dim levelPointer As Integer = 1
'This section of code defines a reader to read in current dates, allowing the day display code to update the background
'First, label up and tag the key controls...
For loopCounter = 0 To 2
'Work out the dates we're going to be playing with...
tempDate = paramDate.AddMonths(loopCounter - 1)
tempDate = New Date(tempDate.Year(), tempDate.Month(), 1)
'Fill in the blanks for the years, months and days...
For innerLoop = mcYear To mcDay
monthCtl(mcYear, loopCounter).Tag = tempDate
monthCtl(mcYear, loopCounter).Text = tempDate.Year()
Next innerLoop
Next loopCounter
'Display the year separators...
yearSep1.Visible = monthCtl(mcYear, 0).Text <> monthCtl(mcYear, 1).Text
yearSep2.Visible = monthCtl(mcYear, 1).Text <> monthCtl(mcYear, 2).Text
'We need to loop through all the controls in the form and figure out which calendar group each control is in. From there we can
'assign each day number based on the calendar group's month and year. The grouping is also significant for days that should be
'hidden...
For Each dayCtl In datePanel.Controls
If dayCtl.Name.StartsWith("day") Then
'Get the number substring from the control and convert it to an integer...
dayNum = Convert.ToInt16(dayCtl.Name.Substring(3))
calNum = Int((dayNum) / 42)
'Populate the tag and text based on the values stored in the month control at the top of the block...
dayCtl.Tag = DateAdd(DateInterval.Day, dayNum - (calNum * 42), monthCtl(mcDay, calNum).Tag)
dayCtl.Text = dayCtl.Tag.Day().ToString()
'The control should only be visible if it's within the bounds of the current month...
[color=red]dayCtl.Visible = dayCtl.Tag.Month().Equals(monthCtl(mcMonth, calNum).Tag.month())[/color]
If dayCtl.Tag.Equals(Now().Date()) Then 'Format the day boxes...
dayCtl.ForeColor = todayColor
Else
dayCtl.ForeColor = Color.Black
End If
If Not dayCtl.BackColor.Equals(Color.FromKnownColor(KnownColor.Control)) AndAlso _
dayCtl.Tag.DayOfWeek = 0 Or dayCtl.Tag.DayOfWeek = 6 Then
dayCtl.BackColor = Color.FromKnownColor(KnownColor.ControlLightLight)
Else
dayCtl.BackColor = Color.FromKnownColor(KnownColor.Control)
End If
End If
Next dayCtl
End Sub
monthCtl is simply an array that contains a set of references to objects on the form (labels). The yearSeps are two picture boxes that are turned on and off between years.
Thanks in advance,
Paul.