The following code provides the VB.NET implementation of the CustomCalendar class.
VB.NET |
Copy Code |
Imports System Imports System.Drawing Imports System.Collections Imports Xceed.Editors Public Cass CustomCalendar Inherits WinCalendar Public Sub New( ByVal specialOccasions As ArrayList ) MyBase.New( True, True ) m_specialOccasions = specialOccasions Me.Width = Me.Width * 2 Me.Height = Me.Height * 2 End Sub Public ReadOnly Property SpecialOccasions As ArrayList Get Return m_specialOccasions End Get End Property Protected Overrides Readonly Property DefaultShowPreviewDays As Boolean Get Return False End Get End Property Protected Overrides Sub OnPaintDayBackground(ByVal e As PaintDayEventArgs) Dim occasion As SpecialOccasion For Each occasion In m_specialOccasions If occasion.SpecialDate = e.Value And occasion.RepeatPattern = RepeatPattern.Once Or _ occasion.RepeatPattern = RepeatPattern.EveryDay Or _ occasion.SpecialDate.DayOfWeek = e.Value.DayOfWeek And _ occasion.RepeatPattern = RepeatPattern.EveryWeek) Or _ (occasion.SpecialDate.Day = e.Value.Day And _ occasion.RepeatPattern = RepeatPattern.EveryMonth) Or _ (occasion.SpecialDate.Month = e.Value.Month And occasion.SpecialDate.Day = e.Value.Day And _ occasion.RepeatPattern = RepeatPattern.EveryYear) Then e.Graphics.DrawImage(occasion.Image, e.ClipRectangle) End If Next occasion End Sub Protected Overrides Sub OnPaintDay(ByVal e As PaintDayEventArgs) Dim occasion As SpecialOccasion For Each occasion In m_specialOccasions If occasion.SpecialDate = e.Value And occasion.RepeatPattern = RepeatPattern.Once Or _ occasion.RepeatPattern = RepeatPattern.EveryDay Or _ (occasion.SpecialDate.DayOfWeek = e.Value.DayOfWeek And _ occasion.RepeatPattern = RepeatPattern.EveryWeek) Or _ (occasion.SpecialDate.Day = e.Value.Day And _ occasion.RepeatPattern = RepeatPattern.EveryMonth) Or _ (occasion.SpecialDate.Month = e.Value.Month And occasion.SpecialDate.Day = e.Value.Day And _ occasion.RepeatPattern = RepeatPattern.EveryYear) Then If occasion.PaintText Then MyBase.OnPaintDay(e) End If Return End If Next occasion MyBase.OnPaintDay(e) End Sub Private m_specialOccasions As ArrayList = Nothing End Class Public Class SpecialOccasion Public Sub New( ByVal specialDate As DateTime, ByVal imagePath As String, ByVal repeatPattern As RepeatPattern, ByVal paintText As Boolean ) If( imagePath = string.Empty ) Then Throw New ArgumentNullException( "imagePath", "A path to an image must be provided" ) End If m_date = specialDate m_imagePath = imagePath m_repeatPattern = repeatPattern m_paintText = paintText End Sub Public ReadOnly Property SpecialDate As DateTime Get Return m_date End Get End Property Public ReadOnly Property ImagePath As String Get Return m_imagePath End Get End Property Public ReadOnly Property RepeatPattern As RepeatPattern Get Return m_repeatPattern End Get End Property Public ReadOnly Property PaintText As Boolean Get Return m_paintText End Get End Property Private m_repeatPattern As RepeatPattern = RepeatPattern.Once Private m_date As DateTime = DateTime.MinValue Private m_imagePath As String = String.Empty Private m_paintText As Boolean = True End Class Public Enum RepeatPattern Once EveryDay EveryWeek EveryMonth EveryYear End Enum |