Class SfCalendar
Represents a Windows control that enables the user to select a date using a visual monthly calendar display with easy navigation between different views. This control provide options to mark the special dates and advanced customization options to cells.
Inherited Members
Namespace: Syncfusion.WinForms.Input
Assembly: Syncfusion.SfInput.WinForms.dll
Syntax
public class SfCalendar : BaseControl, IThemeProvider, IVisualStyle, IDisposable
Examples
This example shows how to initialize the SfCalendar control.
//Create the calendar.
SfCalendar sfCalendar1 = new SfCalendar();
// Set the calendar location.
sfCalendar1.Location = new Point(51, 123);
// Change the color.
sfCalendar1.VisualStyle.Header.BackColor = Color.Purple;
sfCalendar1.VisualStyle.Header.ForeColor = Color.Yellow;
sfCalendar1.VisualStyle.Grid.TrailingCellForeColor = Color.Gray;
// Add dates to BlackoutDates array.
sfCalendar1.BlackoutDates =new DateTime[] {new DateTime(2017, 12, 15),new DateTime(2017, 11, 30)};
// Add dates to SpecialDates array.
sfCalendar1.SpecialDates =new SpecialDate[] {new SpecialDate() { BackColor = Color.Red, ForeColor = Color.White, Value = new DateTime(2017, 12, 13)} ,
new SpecialDate() { BackColor = Color.Green, ForeColor = Color.White, Value = new DateTime(2017, 11, 27) } };
// Configure the calendar to display in 7 weeks in month view.
sfCalendar1.NumberOfWeeksInView = 7;
// Set week to begin on Monday.
sfCalendar1.FirstDayOfWeek = DayOfWeek.Monday;
// Set the maximum visible date on the calendar to 12/31/2019.
sfCalendar1.MaxDate = new DateTime(2019, 12, 31);
// Set the minimum visible date on calendar to 01/01/2017.
sfCalendar1.MinDate = new DateTime(2017, 1, 1);
// Configure the calendar to allow multiple dates selection.
sfCalendar1.AllowMultipleSelection = true;
// Do not highlight today's date.
sfCalendar1.HighlightTodayCell = false;
// Show the week numbers to the left of each week.
sfCalendar1.ShowWeekNumbers = true;
Constructors
SfCalendar()
Initializes a new instance of the SfCalendar class.
Declaration
public SfCalendar()
Properties
AccessibilityEnabled
Gets or sets a value indicating whether the control should enable Accessibility support in SfCalendar
Declaration
public bool AccessibilityEnabled { get; set; }
Property Value
Type |
---|
System.Boolean |
AllowMultipleSelection
Gets or sets a value indicating whether to allow multiple date selection in SfCalendar.
Declaration
public bool AllowMultipleSelection { get; set; }
Property Value
Type |
---|
System.Boolean |
BackColor
Gets a Value indicating the BackColor of grid in SfCalendar when animation occurs
Declaration
public Color BackColor { get; }
Property Value
Type |
---|
System.Drawing.Color |
BlackoutDates
Gets or sets the collection of dates for blocking from selection and user interaction in SfCalendar.
Declaration
public List<DateTime> BlackoutDates { get; set; }
Property Value
Type |
---|
System.Collections.Generic.List<System.DateTime> |
Culture
Gets or sets the System.Globalization.CultureInfo that represents formatting for date time in SfCalendar.
Declaration
public CultureInfo Culture { get; set; }
Property Value
Type |
---|
System.Globalization.CultureInfo |
DefaultSize
Gets the default size of the SfCalendar control.
Declaration
protected override Size DefaultSize { get; }
Property Value
Type |
---|
System.Drawing.Size |
EnableAnimation
Gets or sets a value indicating whether to animate the Calendar View while Navigate from one view to another view.
Declaration
public bool EnableAnimation { get; set; }
Property Value
Type |
---|
System.Boolean |
FirstDayOfWeek
Gets or sets the first System.DayOfWeek in SfCalendar
Declaration
public DayOfWeek FirstDayOfWeek { get; set; }
Property Value
Type |
---|
System.DayOfWeek |
FooterHeight
Gets or sets the height of the Footer in SfCalendar. Footer contains the Today and None button.
Declaration
public int FooterHeight { get; set; }
Property Value
Type |
---|
System.Int32 |
HeaderHeight
Gets or sets the header height of SfCalendar.
Declaration
public int HeaderHeight { get; set; }
Property Value
Type |
---|
System.Int32 |
HighlightTodayCell
Gets or sets a value indicating whether Today cell highlighted even selected date is different than Today in SfCalendar.
Declaration
public bool HighlightTodayCell { get; set; }
Property Value
Type |
---|
System.Boolean |
MaxDate
Gets or sets a value indicating maximum value constraint for SfCalendar. This restricts to set the SelectedDate greater than specific DateTime.
Declaration
public DateTime MaxDate { get; set; }
Property Value
Type |
---|
System.DateTime |
Remarks
MaxDate should be greater than MinDate of SfCalendar.
MinDate
Gets or sets a value indicating minimum value constraint for SfCalendar. This restricts to set the SelectedDate lesser than specific DateTime.
Declaration
public DateTime MinDate { get; set; }
Property Value
Type |
---|
System.DateTime |
Remarks
MaxDate should be lesser than MaxDate of SfCalendar.
MinimumSize
Gets or sets the minimum size of of the SfCalendar control.
Declaration
public override Size MinimumSize { get; set; }
Property Value
Type |
---|
System.Drawing.Size |
NavigationButtonAlignment
Gets or sets the side value indicating how the navigation buttons should align relative to the Calendar Header.
Declaration
public NavigationButtonAlignment NavigationButtonAlignment { get; set; }
Property Value
Type |
---|
NavigationButtonAlignment |
NumberOfWeeksInView
Gets or sets the value to indicates the number of weeks shown in the month view.
Declaration
public int NumberOfWeeksInView { get; set; }
Property Value
Type |
---|
System.Int32 |
RightToLeft
Gets or sets a value indicating whether control's elements are aligned in right-to-left layout or not.
Declaration
public override RightToLeft RightToLeft { get; set; }
Property Value
Type |
---|
System.Windows.Forms.RightToLeft |
SelectedDate
Gets or sets the value indicating the selected date of the SfCalendar.
Declaration
public DateTime? SelectedDate { get; set; }
Property Value
Type |
---|
System.Nullable<System.DateTime> |
Remarks
SelectedDates
Declaration
public ObservableCollection<DateTime> SelectedDates { get; }
Property Value
Type |
---|
System.Collections.ObjectModel.ObservableCollection<System.DateTime> |
ShowAbbreviatedDayNames
Gets or sets a value indicating whether to show the week day names with abbreviated format in header of SfCalendar.
Declaration
public bool ShowAbbreviatedDayNames { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowFooter
Gets or sets a value indicating whether the visibility of the footer of SfCalendar should be visible.
Declaration
public bool ShowFooter { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowHorizontalSplitter
Gets or sets a value indicating whether the dates of each rows in the SfCalendar are separated with horizontal splitter.
Declaration
public bool ShowHorizontalSplitter { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowNavigationButton
Gets or sets a value indicating whether to show the navigation buttons which used to move between views in SfCalendar.
Declaration
public bool ShowNavigationButton { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowNone
Gets or sets a value indicating whether visibility of none button in footer of SfCalendar
Declaration
public bool ShowNone { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
ShowNone property will be work only when show ShowFooter is true
ShowToday
Gets or sets a value indicating whether visibility of today button in footer of SfCalendar
Declaration
public bool ShowToday { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
ShowToday property will be work only when show ShowFooter is true
ShowToolTip
Gets or sets a value indicating whether to show or hide the tooltip.
Declaration
public bool ShowToolTip { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowVerticalSplitter
Gets or sets a value indicating whether the dates of each columns in the SfCalendar are separated with vertical splitter.
Declaration
public bool ShowVerticalSplitter { get; set; }
Property Value
Type |
---|
System.Boolean |
ShowWeekNumbers
Gets or sets a value indicating whether the calendar will display week numbers (1 to 52) to the left of each rows in SfCalendar.
Declaration
public bool ShowWeekNumbers { get; set; }
Property Value
Type |
---|
System.Boolean |
SpecialDates
Declaration
public List<SpecialDate> SpecialDates { get; set; }
Property Value
Type |
---|
System.Collections.Generic.List<SpecialDate> |
Style
Gets the CalendarVisualStyle value to customize the appearance of the SfCalendar.
Declaration
public CalendarVisualStyle Style { get; }
Property Value
Type |
---|
CalendarVisualStyle |
TrailingDatesVisible
Gets or sets a value indicating whether the dates of previous and following months visible in current view of SfCalendar.
Declaration
public bool TrailingDatesVisible { get; set; }
Property Value
Type |
---|
System.Boolean |
ViewMode
Gets or sets a value indicating the possible view types for navigation through user interaction in SfCalendar.
Declaration
public CalendarViewType ViewMode { get; set; }
Property Value
Type |
---|
CalendarViewType |
Methods
ClearSelection(DateTime)
Clear the selected dates and set the SelectedDate based on given value.
Declaration
public bool ClearSelection(DateTime dateTime)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | dateTime | The DateTime which has to be set as SelectedDate after clear selection. |
Returns
Type | Description |
---|---|
System.Boolean | Returns if the selected dates has been cleared successfully. |
Remarks
If value given for selected date is not within MinDate and MaxDate range, it will return false. Then the selection will be cleared and the first date in the SelectedDates collection will set as SelectedDate.
CreateAccessibilityInstance()
Creates a new accessibility object in SfCalendar.
Declaration
protected override AccessibleObject CreateAccessibilityInstance()
Returns
Type | Description |
---|---|
System.Windows.Forms.AccessibleObject | A new System.Windows.Forms.AccessibleObject for the SfCalendar, when AccessibilityEnabled is set as true |
Dispose(Boolean)
Releases all resources used by this Controls component.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | Dispose the resources used by Controls component. |
GetControlName(String)
Helps to apply the ControlName settings in control
Declaration
public override string GetControlName(string controlName)
Parameters
Type | Name | Description |
---|---|---|
System.String | controlName | The name of the control |
Returns
Type | Description |
---|---|
System.String | The name of the control |
Overrides
GoToDate(DateTime)
Move the current view of SfCalendar to the date based on given value. Return value as false when the date is not fall within min max range or Blackout dates contains the date.
Declaration
public bool GoToDate(DateTime date)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | date | The date where the view has to be navigate. |
Returns
Type | Description |
---|---|
System.Boolean | Returns if the navigation to the date is success based on MinDate and MaxDate Validation before navigate. |
Remarks
Navigation will be failed, if the value given for navigate to date is not within MinDate and MaxDate range or contains in BlackoutDates.
OnLayout(LayoutEventArgs)
Raises the System.Windows.Forms.Control.Layout event.
Declaration
protected override void OnLayout(LayoutEventArgs levent)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.LayoutEventArgs | levent | A System.Windows.Forms.LayoutEventArgs that contains the event data. |
OnMouseWheel(MouseEventArgs)
Event will trigger when the mouse is scrolling
Declaration
protected override void OnMouseWheel(MouseEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.MouseEventArgs | e | An System.MouseEventArgs that contains the event Mouse pointer co-ordinates. |
OnParentRightToLeftChanged(EventArgs)
Raises the SfCalendar Parent RightToLeft changed event.
Declaration
protected override void OnParentRightToLeftChanged(EventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.EventArgs | e | An System.EventArgs that contains the event data. |
OnThemeNameChanged(String)
Helps to apply the ThemeName settings in control
Declaration
public override void OnThemeNameChanged(string themeName)
Parameters
Type | Name | Description |
---|---|---|
System.String | themeName | The ThemeName of the Control |
Overrides
ProcessCmdKey(ref Message, Keys)
Processes a command key.
Declaration
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.Message | msg | A System.Windows.Forms.Message, passed by reference, that represents the window message to process. |
System.Windows.Forms.Keys | keyData | One of the System.Windows.Forms.Keys values that represents the key to process. |
Returns
Type | Description |
---|---|
System.Boolean | true if the character was processed by the control; otherwise, false. |
RaiseThemeChanged(Object, ThemeChangedEventArgs)
Raises the
Declaration
protected override void RaiseThemeChanged(object sender, ThemeChangedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The sender value. |
ThemeChangedEventArgs | args | A ThemeChangedEventArgs contains the event data. |
Overrides
ResetRightToLeft()
Resets the RightToLeft back to its default value.
Declaration
public override void ResetRightToLeft()
SelectDates(SelectionRange, Boolean)
Select the Single Range of Multiple Dates while Allow Multiple selection is true, else return false.
Declaration
public bool SelectDates(SelectionRange range, bool ignoreSelectionOnValidation)
Parameters
Type | Name | Description |
---|---|---|
System.Windows.Forms.SelectionRange | range | Date selection range in calendar. |
System.Boolean | ignoreSelectionOnValidation | Ignore the selection if validation failed. The validation will be failed if the range falls in MinMaxDate or contains disabled dates |
Returns
Type | Description |
---|---|
System.Boolean | Return value as false even the dates are not fall within minMax range or Blackout dates contains the date. |
SetBoundsCore(Int32, Int32, Int32, Int32, BoundsSpecified)
Performs the work of setting the specified bounds of this control.
Declaration
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | The new System.Windows.Forms.Control.Left property value of the control. |
System.Int32 | y | The new System.Windows.Forms.Control.Top property value of the control. |
System.Int32 | width | The new System.Windows.Forms.Control.Width property value of the control. |
System.Int32 | height | The new System.Windows.Forms.Control.Height property value of the control. |
System.Windows.Forms.BoundsSpecified | specified | A bitwise combination of the System.Windows.Forms.BoundsSpecified values. |
Events
CellClick
Occurs when clicking the calendar cell.
Declaration
public event EventHandler<CalendarCellEventArgs> CellClick
Event Type
Type |
---|
System.EventHandler<CalendarCellEventArgs> |
DrawCell
Occurs on Draw the calendar items.
Declaration
public event DrawCellEventHandler DrawCell
Event Type
Type |
---|
DrawCellEventHandler |
Navigating
Occurs when navigating from one month to another in Calendar
Declaration
public event NavigatingEventHandler Navigating
Event Type
Type |
---|
NavigatingEventHandler |
Remarks
Navigating event occurs when press Navigation buttons to move or previous month, year or decade in Calendar.
SelectionChanged
Occurs after the selected date changed in Calendar.
Declaration
public event SelectionChangedEventHandler SelectionChanged
Event Type
Type |
---|
SelectionChangedEventHandler |
SelectionChanging
Occurs before the selected date changed in Calendar.
Declaration
public event SelectionChangingEventHandler SelectionChanging
Event Type
Type |
---|
SelectionChangingEventHandler |
ThemeChanged
Occurs when theme name of the SfCalendar has changed.
Declaration
public event ThemeChangedEventHandler ThemeChanged
Event Type
Type |
---|
ThemeChangedEventHandler |
ToolTipOpening
Occurs when mouse hover the cell in calendar
Declaration
public event ToolTipOpeningEventHandler ToolTipOpening
Event Type
Type |
---|
ToolTipOpeningEventHandler |
ViewChanging
Occurs when calendar ViewType is changing.
Declaration
public event ViewChangingEventHandler ViewChanging
Event Type
Type |
---|
ViewChangingEventHandler |
Remarks
ViewChanging event occurs when click on the Calendar Header text to change the view from one view to another view