As you may already know, Q1 2012 RadControls for WinForms brought to you one much requested feature- native printing support for RadGridView and RadScheduler. Utilizing its capabilities it is as easy as pie to send the data from your control to a printer by calling a single method. However, there are also a variety of options that allow you to customize the appearance of your pages. With this post, we will take a closer look at the features and options of printing that RadScheduler provides out-of-the-box.

Let’s say we have a RadScheduler populated with appointments and we want to implement a feature which will print the appointments for the next five days that are between 7AM and 7PM. First we need to create a RadPrintDocument instance and associate it with our scheduler:
RadPrintDocument document = new RadPrintDocument(); 
document.AssociatedObject = this.radScheduler1;

RadPrintDocument is a component that manages the whole printing process. We can use its properties to customize the general appearance of all pages by setting header, footer and/or watermark. Let’s add a header to our pages and also add the current page number in one of the bottom corners of each page:
document.MiddleHeader = "Printed from RadScheduler";
document.RightFooter = "Page " + RadPrintDocument.PageNumberString + " of " + RadPrintDocument.TotalPagesString;
document.ReverseFooterOnEvenPages = true;

When the ReverseFooterOnEvenPages property is set to true, the text of the RightFooter is displayed at the bottom left corner of the page. This property allows us for example to keep the current page number in the outer corner when we put our pages next to each other in a folder or a notebook.
Next, we should choose the way that our appointments will be arranged over the pages. This can be achieved by assigning one of the SchedulerPrintStyle inheritors to RadScheduler:
SchedulerDailyPrintStyle dailyStyle = new SchedulerDailyPrintStyle();
this.radScheduler1.PrintStyle = dailyStyle;

You can pick one of the four predefined print styles: SchedulerDailyPrintStyle, SchedulerWeeklyPrintStyle, SchedulerMonthlyPrintStyle, SchedulerDetailsPrintStyle. Choosing different styles will lead to a totally different appearance of your pages. All print styles share some common options and also provide options specific to the concrete style. Now let’s set the date and time intervals we want to print the appointments from:
dailyStyle.DateStartRange = DateTime.Today;
dailyStyle.DateEndRange = DateTime.Today.AddDays(5);
dailyStyle.TimeStartRange = TimeSpan.FromHours(7);
dailyStyle.TimeEndRange = TimeSpan.FromHours(19);

By setting the DateStartRange and DateEndRange properties we can pick the date range we want to print. The TimeStartRange and TimeEndRange properties stand for each day and indicate the time interval we want to print appointments from. For example, if we do not care of appointments that start later than 19 o’clock or end before 7 o’clock we can set these properties as in the above code snippet.

Another useful feature is the area for handwritten notes which you can add to each page. You can choose between a blank area, a lined area or both. To enable each of these features, you should set the following properties:
dailyStyle.ShowNotesArea = true;
dailyStyle.ShowLinedNotesArea = true;

In all print styles except the SchedulerDetailsPrintStyle, there is a title box which contains the current date and a small calendar at the top of each page. It lets you easily figure out the days that you have appointments on, since the busy days on this calendar are bold. These features are turned on by default and you can enable or disable them by setting the following properties:
dailyStyle.DrawPageTitle = true;
dailyStyle.DrawPageTitleCalendar = true;

Now let’s say we want to modify the default fonts of our pages:
dailyStyle.DateHeadingFont = new Font("Segoe UI", 8, FontStyle.Bold);
dailyStyle.AppointmentFont = new Font("Verdana", 10, FontStyle.Regular);
dailyStyle.PageHeadingFont = new Font("Times New Roman", 16, FontStyle.Bold);

As you can see, there is a separate font property for different parts of the page.

Now, let’s tweak the appearance of our pages a bit further by utilizing the CellElementFormatting event. For example, let’s say we want to add a background fill of the cells between 12 o’clock and 13 o’clock.
dailyStyle.CellElementFormatting += new PrintSchedulerCellEventHandler(dailyStyle_CellElementFormatting);
void dailyStyle_CellElementFormatting(object sender, PrintSchedulerCellEventArgs e)
      if (e.CellElement.Date.Hour >= 12 && e.CellElement.Date.Hour < 13)
          e.CellElement.DrawFill = true;
          e.CellElement.BackColor = Color.OrangeRed;

Now that we are done setting up the print style, we want to preview the result. We can either preview the result in a RadPrintPreviewDialog or send it directly to your printer by using the Print method of our RadPrintDocument.

Warning: If you haven’t set the print style correctly, printing without previewing might lead to spending lots of paper :) .

Using the following code we take a quick look at the result in a preview dialog:
RadPrintPreviewDialog previewDialog = new RadPrintPreviewDialog(document);

Finally, here is how the pages look like:

RadScheduler for WinForms Printing for WinForms


Now that you know how to set up a print style, you can also try using the rest of the print styles with different setting combinations. And feel free to share your feedback.

Download RadControls for WinForms by Telerik

About the Author

Nikolay Diyanov

Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.

Find him on Twitter @n_diyanov or on LinkedIn.

Related Posts


Comments are disabled in preview mode.