Xceed Grid for WinForms v4.3 Documentation
Headers

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > Editor Controls > WinCalendar control > Headers

Month header

The WinCalendar's navigation header is represented by the MonthHeader class and is accessible via the calendar's MonthHeader property. The month header is composed of 3 WinButton controls: the PreviousButton which is used to navigate to the previous month, the NextButton which is used to navigate to the next month, and the TitleButton which is used to display, by default, the name of the month and the year, as well as to select a month to jump to. 

A month header is not active (and thus does not display the previous and next navigation buttons) unless the mouse is over one of the months. In that case, only the month header of that month is active.  

All three navigation buttons in the month header can be used to navigate to another month. The "Previous" button navigates to the month prior to the currently active month, the "Next" button navigates to the month after the currently active month, and the "Title" button allows you to navigate to one of the 5 months preceding or following the currently active month. 

When navigating through the grid with one of the 3 navigation buttons in the month header, the currently selected month will be replaced by the previous, next, or selected month. For example, in the first image below, December's "Next" button is pressed. As a result, in the second image, January is moved to where December was. This also offsets December and November, removes October, and adds February.  

The properties of the navigation buttons in the month header can be modified; however, the navigation buttons themselves cannot be replaced with another WinButton control. Via the designer, modifications made to the navigation buttons will automatically be applied to the WinCalendar. Via code, if the properties of the navigation buttons are modified after the WinCalendar control has been added to a form, a call to the Refresh method is required in order for the modifications to be applied. If the properties are set before the WinCalendar control is added to a form, then a call to Refresh is not required.

VB.NET
Copy Code
Dim calendar As New WinCalendar( True, True )

' Modify the ForeColor property of an existing calendar

calendar.MonthHeader.TitleButton.ForeColor = Color.Orange

calendar.Refresh()

calendar.Location = New Point( 10, 10 )

Me.Controls.Add( calendar )
C#
Copy Code
WinCalendar calendar = new WinCalendar( true, true );

// Modify the ForeColor property of an existing calendar

calendar.MonthHeader.TitleButton.ForeColor = Color.Orange;

calendar.Refresh();

calendar.Location = new Point( 10, 10 );

this.Controls.Add( calendar );

The MonthHeader cannot be removed from the calendar; however, it can be hidden from view by setting its Height property to 0. Note that setting each navigation button's Visible property to false will not hide them.

VB.NET
Copy Code
Dim calendar As New WinCalendar( True, True )

calendar.MonthHeader.Height = 0    

calendar.Location = New Point( 10, 10 )

Me.Controls.Add( calendar )
C#
Copy Code
WinCalendar calendar = new WinCalendar( true, true );

calendar.MonthHeader.Height = 0;     

calendar.Location = new Point( 10, 10 );

this.Controls.Add( calendar );

The appearance of the navigation buttons can be modified by assigning a new instance of the ButtonType class to their respective ButtonType properties. For example, in the image below, the ImageType of the "Previous" navigation button was set to SpinUp, the "Next" button's to SpinDown, and the "Title" button's to User, while the BackgroundImageType of all the navigation buttons was set to Close.

VB.NET
Copy Code
Dim calendar As New WinCalendar( True, True )

Dim previous As New ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.SpinUp )

Dim next As New ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.SpinDown )

Dim title As New ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.User )

calendar.MonthHeader.PreviousButton.ButtonType = previous

calendar.MonthHeader.NextButton.ButtonType = next

calendar.MonthHeader.TitleButton.ButtonType = title

calendar.Location = New Point( 10, 10 )

Me.Controls.Add( calendar )
C#
Copy Code
WinCalendar calendar = new WinCalendar( true, true );     

ButtonType previous = new ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.SpinUp );

ButtonType next = new ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.SpinDown );

ButtonType title = new ButtonType( ButtonBackgroundImageType.Close, ButtonImageType.User );

calendar.MonthHeader.PreviousButton.ButtonType = previous;

calendar.MonthHeader.NextButton.ButtonType = next;

calendar.MonthHeader.TitleButton.ButtonType = title;

calendar.Location = new Point( 10, 10 );

this.Controls.Add( calendar );

The text displayed in the TitleButton can be modified using the WinCalendar's FormatTitleButtonText event. This event is raised for each month that is about to be painted in the calendar so you can provide a custom title. 

The FormatTitleButtonTextEventArgs that are received in the FormatTitleButtonText event contain the Text and Date of the month that is about to be painted. Keep in mind that the Date will always be set to the first day of the month. The calendar's SelectedDate or CurrentDate properties can be consulted to retrieve the selected or current date (the one that has the focus rectangle). 

By default, the full name of the month followed by the 4 digit year is displayed using the "MMMM yyyy" format pattern. The various format characters and patterns that can be used can be found in the Framework's DateTimeFormatInfo class topic.

VB.NET
Copy Code
Dim calendar As New WinCalendar( True, True )

' Subscribe to the FormatTitleButtonText event

AddHandler calendar.FormatTitleButtonText, AddressOf Me.format_title

' 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( 10, 10 )

Me.Controls.Add( calendar )

Private Sub format_title( ByVal sender As Object, ByVal e As FormatTitleButtonTextEventArgs )

  'Format the date displayed in the TitleButton using the abbreviated month and year format pattern.

  e.Text = e.Date.ToString( "-- MMM yy -- " )

End Sub
C#
Copy Code
WinCalendar calendar = new WinCalendar( true, true );

// Subscribe to the FormatTitleButtonText event

calendar.FormatTitleButtonText += new FormatTitleButtonTextEventHandler( this.format_title );

// 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( 10, 10 );

this.Controls.Add( calendar );

private void format_title( object sender, FormatTitleButtonTextEventArgs e )

{

    // Format the date displayed in the TitleButton

    // using the abbreviated month and year format pattern.

    e.Text = e.Date.ToString( "-- MMM yy -- " );   

}

Weekdays header

The names of the days of the week are displayed above the calendar days in the WeekDaysHeader. The WinCalendar control adapts to the system's regional settings therefore, the names of the days of the week, as well as the first day of the week, can vary depending on the current culture's datetime format. For example, in the image below, the first calendar uses the English (Canada) regional settings, therefore, the names of the days of the week will be Sunday, Monday, Tuesday, etc., and the first day of the week will be Sunday. In the second calendar, the German (Germany) regional settings are used, therefore, Sonntag, Montag, Dienstag, etc., will be used as the weekday names, and Montag (Monday) will be used as the first day of the week (as defined by the current culture's datetime format). 

The names of the days of the week can be retrieved and modified via the WeekDaysHeader's DayNames property. By default, these values will be set to the names of the days of the week as defined by the current culture's datetime format, however they can also be modified to contain custom names such as 1, 2, 3, etc.
VB.NET
Copy Code
Dim names( 6 ) As String

names( 0 ) = "1"

names( 1 ) = "2"

names( 2 ) = "3"

names( 3 ) = "4"

names( 4 ) = "5"

names( 5 ) = "6"

names( 6 ) = "7"

winCalendar1.WeekDaysHeader.DayNames = names
C#
Copy Code
string[] names = new string[ 7 ];

names[ 0 ] = "1";

names[ 1 ] = "2";

names[ 2 ] = "3";

names[ 3 ] = "4";

names[ 4 ] = "5";

names[ 5 ] = "6";

names[ 6 ] = "7";

winCalendar1.WeekDaysHeader.DayNames = names;

Note that Sunday is always at index 0 regardless of the first day of the week defined by the current culture's datetime format. 

By default, only the first letter of each weekday name is displayed in the WeekDaysHeader. The number of characters that can potentially be displayed in the header is set via the MaxDayNameChars property.

VB.NET Copy Code
WinCalendar1.WeekDaysHeaders.MaxDayNameChars = 3
C# Copy Code
winCalendar1.WeekDaysHeaders.MaxDayNameChars = 3;
The actual number of characters that are displayed depends on the size of the font that is being used, the available space, and the length of the names of the days of the week. For example, the "W" in Wednesday is larger than the "F" in Friday. Therefore, there will only be enough space to   fit the "W" for Wednesday and "Fri" for Friday.