-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from telerik/new-kb-calendar-hide-month-days-…
…63a6741d7cf7486fb21da6a79156de6d Added new kb article calendar-hide-month-days
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: Hiding Days Not of the Current Month in RadCalendar for WinForms | ||
description: Learn how to customize the RadCalendar control to hide days that do not belong to the current month, enhancing the calendar's visual clarity. | ||
type: how-to | ||
page_title: How to Hide Non-Current Month Days in RadCalendar for WinForms | ||
slug: calendar-hide-month-days | ||
tags: calendar, winforms, calendarcell, elementrender, othermonth | ||
res_type: kb | ||
ticketid: 1610791 | ||
--- | ||
|
||
## Environment | ||
|
||
|Product Version|Product|Author| | ||
|----|----|----| | ||
|2024.3.806|RadCalendar for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| | ||
|
||
## Description | ||
|
||
In certain scenarios, you might want to enhance the visual clarity of the RadCalendar by hiding days that do not belong to the current month. This article guides you through the process of achieving such customization, particularly when the `AllowMultipleView` property is set to `true`. | ||
|
||
![calendar-hide-month-days-calendar 001](images/calendar-hide-month-days-calendar001.png) | ||
|
||
## Solution | ||
|
||
To hide days that are not part of the current month in RadCalendar, handle the `ElementRender` event. Within this event handler, use the `OtherMonth` property of `CalendarCellElement` to determine if a day belongs to the current month. If `OtherMonth` returns `true`, set the cell's visibility to `Hidden`. | ||
|
||
Here's a code snippet demonstrating how to implement this solution: | ||
|
||
````C# | ||
private void RadCalendar1_ElementRender(object sender, RenderElementEventArgs e) | ||
{ | ||
var cell = e.Element as CalendarCellElement; | ||
if (cell.OtherMonth) | ||
{ | ||
cell.Visibility = ElementVisibility.Hidden; | ||
} | ||
} | ||
```` | ||
|
||
To apply this approach, first, ensure the `AllowMultipleView` property of your RadCalendar is set according to your requirements. Next, subscribe to the `ElementRender` event of RadCalendar and include the code above in your event handler. This customization will hide all days that do not belong to the current month, providing a cleaner and more focused calendar view. | ||
|
||
## Notes | ||
|
||
- The `ElementRender` event is a key point for customizing the appearance of calendar cells. | ||
- The `OtherMonth` property is crucial for identifying days that belong to months other than the current one. | ||
|
||
## See Also | ||
* [RadCalendar Documentation](https://docs.telerik.com/devtools/winforms/controls/calendar/overview) |