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;
document.MiddleHeader =
"Printed from RadScheduler"
;
document.RightFooter =
"Page "
+ RadPrintDocument.PageNumberString +
" of "
+ RadPrintDocument.TotalPagesString;
document.ReverseFooterOnEvenPages =
true
;
SchedulerDailyPrintStyle dailyStyle =
new
SchedulerDailyPrintStyle();
this
.radScheduler1.PrintStyle = dailyStyle;
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
;
dailyStyle.DrawPageTitle =
true
;
dailyStyle.DrawPageTitleCalendar =
true
;
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);
previewDialog.ShowDialog();
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.
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.