The WinCalendar control exposes the margins of various calendar regions. These include the calendar's margins, the margin's around each month in the calendar, the margins around all the days (including preview days) in each month, as well as the margins surrounding each individual day in the calendar.
The margins that surround the calendar are exposed via the Margins property. By default, the top, right and left margins are set to 1 pixel. The bottom margin is set to 17 pixels since, initially, it contains the "Today" and "None" buttons. In the image below, all four of the calendar's margins are set to 10 pixels and are represented by the grayed section.
See example
Dim calendar As New WinCalendar()
calendar .Margins = New Margins( 10 )
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar();
calendar.Margins = new Margins( 10 );
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
The margins that surround each month in a calendar are exposed via the MonthMargins property. By default, the top margin is set to 0 pixels, the left and right margins to 2 pixels, and the bottom margin to 4 pixels. In the image below, all four of the month margins are set to 10 pixels and are represented by the grayed section.
See example
Dim calendar As New WinCalendar()
calendar.Margins = New Margins( 0 )
calendar.MonthMargins = New Margins( 10 )
' Adjust the size so 4 months will fit into the calendar
calendar.Height = calendar.Height * 2
calendar.Width = calendar.Width * 2
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar();
calendar.Margins = new Margins( 0 );
calendar.MonthMargins = new Margins( 10 );
// Adjust the size so 4 months will fit into the calendar
calendar.Height = calendar.Height * 2;
calendar.Width = calendar.Width * 2;
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
In addition to the MonthMargins, the horizontal and vertical spacing between months can be adjusted using the HorizontalSpacing and VerticalSpacing properties. Spacing between months is only taken into consideration when EnableMultipleMonths is set to true (default) and more than 1 month is displayed in the calendar. In the image below, the months have 1 pixel margins and there is a horizontal and vertical spacing of 20 pixels which is represented by the grayed section.
See example
Dim calendar As New WinCalendar()
calendar.Margins = New Margins( 1 )
' The MonthMargins need to be set to one because the DaysBorders
' are painted inside the MonthMargins and we want them to be visible
calendar.MonthMargins = New Margins( 1 )
calendar.HorizontalSpacing = 20
calendar.VerticalSpacing = 20
' Adjust the size so 4 months will fit into the calendar
calendar.Height = ( calendar.Height * 2 ) + calendar.VerticalSpacing
calendar.Width = ( calendar.Width * 2 ) + calendar.HorizontalSpacing
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar()
calendar.Margins = new Margins( 1 )
// The MonthMargins need to be set to one because the DaysBorders
// are painted inside the MonthMargins and we want them to be visible
calendar.MonthMargins = new Margins( 1 )
calendar.HorizontalSpacing = 20;
calendar.VerticalSpacing = 20
// Adjust the size so 4 months will fit into the calendar
calendar.Height = ( calendar.Height * 2 ) + calendar.VerticalSpacing;
calendar.Width = ( calendar.Width * 2 ) + calendar.HorizontalSpacing
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
The margins that surround all the days (including preview days) in each month are exposed via the MonthDaysMargins property. By default, the top, left and right margins are set to 1 pixel, while the bottom margin is set to 2 pixels. In the image below, all four of the margins have been set to 5 pixels and are represented by the grayed section.
See example
Dim calendar As New WinCalendar()
calendar.Margins = New Margins( 1 )
calendar.MonthDaysMargins = New Margins( 5 )
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar();
calendar.Margins = new Margins( 1 );
calendar.MonthDaysMargins = new Margins( 5 );
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
The margins that surround each individual day in the calendar are exposed via the DayMargins property. By default, all four margins are set to 0 pixels. In the image below, all four margins of each day have been set to 5 pixels, and are represented by the grayed section. In order to clarify the image, only the margins that surround the 29th day of September have been grayed. Note that the highlights of the present date ("Today") and selected date, as well as the current date's focus rectangle, are painted within the day's margins.
See example
Dim calendar As New WinCalendar()
calendar.Margins = New Margins( 1 )
calendar.DayMargins = New Margins( 5 )
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar();
calendar.Margins = new Margins( 1 );
calendar.DayMargins = new Margins( 5 );
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
Aside from the margins of various calendar regions, the WinCalendar control also exposes, via the DaysBorders property, the borders that surround each month's days (including preview days).
Each of the four borders is represented by an instance of a BorderInfo class which allows various properties of each border to be configured. For example, in the image below we have remove the left and right borders, set the dashstyle of the top and bottom borders to Dash, and changed the foreground color of the top and bottom borders to orange.
See example
Dim calendar As New WinCalendar( True, True )
calendar.DaysBorders.Left.Visible = False
calendar.DaysBorders.Right.Visible = False
calendar.DaysBorders.Top.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
calendar.DaysBorders.Bottom.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
calendar.DaysBorders.Top.ForeColor = Color.Orange
calendar.DaysBorders.Bottom.ForeColor = Color.Orange
calendar.Location = New Point( 5, 5 )
Me.Controls.Add( calendar )
WinCalendar calendar = new WinCalendar( true, true );
calendar.DaysBorders.Left.Visible = false;
calendar.DaysBorders.Right.Visible = false;
calendar.DaysBorders.Top.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
calendar.DaysBorders.Bottom.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
calendar.DaysBorders.Top.ForeColor = Color.Orange;
calendar.DaysBorders.Bottom.ForeColor = Color.Orange
calendar.Location = new Point( 5, 5 );
this.Controls.Add( calendar );
Note that the borders are painted within the MonthMargins!