Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim graphics As Graphics = e.Graphics
Dim dayBoxWidth As Integer = 0
Dim dayBoxHeight As Integer = 0
Dim firstWeekPosition As Integer = 0
Dim lastWeekPosition As Integer = Height
If WarningDates.Count > 0 Then
Dim calendarRange As SelectionRange = GetDisplayRange(False)
'erstellt eine Liste der Warn-Tage, die im aktuellen
' Anzeigebereich liegen
Dim visibleWarningDates As New List(Of DateTime)()
For Each [date] As DateTime In WarningDates
If [date] >= calendarRange.Start AndAlso [date] <= _
calendarRange.[End] Then
visibleWarningDates.Add([date])
End If
Next
If visibleWarningDates.Count > 0 Then
While (HitTest(25, firstWeekPosition).HitArea <> _
HitArea.PrevMonthDate AndAlso _
HitTest(25, firstWeekPosition).HitArea <> _
HitArea.[Date]) AndAlso _
firstWeekPosition < Height
firstWeekPosition += 1
End While
While (HitTest(25, lastWeekPosition).HitArea <> _
HitArea.NextMonthDate AndAlso _
HitTest(25, lastWeekPosition).HitArea <> _
HitArea.[Date]) AndAlso _
lastWeekPosition >= 0
lastWeekPosition -= 1
End While
If firstWeekPosition > 0 AndAlso lastWeekPosition > 0 Then
dayBoxWidth = Width \ (If(ShowWeekNumbers, 8, 7))
dayBoxHeight = CInt(Math.Truncate(CSng(lastWeekPosition _
- firstWeekPosition) / 6.0F))
Using warningbrush As Brush = New SolidBrush( _
_WarningBackColor)
'Schleife über alle aktuell sichtbaren Warn-Tage
For Each visDate As DateTime In visibleWarningDates
'Nur aktuell nicht-markierte Warn-Tage werden
' hervorgehoben
If Not IsDateSelected(visDate) Then
Dim row As Integer = 0
Dim col As Integer = 0
Dim span As TimeSpan = visDate.Subtract( _
calendarRange.Start)
row = span.Days \ 7
col = span.Days Mod 7
Dim fillRect As New Rectangle _
((col + (If(ShowWeekNumbers, 1, 0))) * _
dayBoxWidth + 2, _
firstWeekPosition + row * dayBoxHeight + _
1, _
dayBoxWidth - 2, dayBoxHeight - 2)
graphics.FillRectangle(warningbrush, _
fillRect)
' Feststellen, ob der aktuelle Warn-Tag
' zusätzlich fett darzustellen ist
Dim makeDateBolded As Boolean = False
For Each boldDate As DateTime In BoldedDates
If boldDate = visDate Then
makeDateBolded = True
End If
Next
Dim Textfont As Font
If makeDateBolded Then
Textfont = New Font(Font.FontFamily, _
Font.Size, FontStyle.Bold)
Else
Textfont = New Font(Font.FontFamily, _
Font.Size, FontStyle.Regular)
End If
TextRenderer.DrawText(graphics, _
visDate.Day.ToString(), _
Textfont, fillRect, _WarningForeColor, _
TextFormatFlags.HorizontalCenter Or _
TextFormatFlags.VerticalCenter)
End If
Next 'for each
End Using 'using brush
End If ' if firstweek ..
End If ' if visiblewarnings
End If ' if warnings
End Sub ' On Paint
Private Function IsDateSelected(ByVal dt As Date) As Boolean
'Die Funktion prüft, ob ein Datum im markierten Bereich liegt
With MyBase.SelectionRange
If .Start <= dt And dt <= .End Then
Return True
End If
End With
Return False
End Function
End Class 'class
End Namespace 'namespace |