Hello,
I am new to Telerik WinControl. I’m using version 2012.3.1017.40.
I was looking for a control for displaying a chart-diagram in a Windows Forms application. I found the controls “RadChart” and “RadChartView”. Because of the advice of use the control “RadChartView” in your documentation I was making first experiences with this control the last days. As I can see so far, this control seems to be a powerful tool. Having created, configured this control and bound data to it I am looking for the possibility to print out the content of this control. In the documentation I have read that RadChartView does not support the functionality to export its content to a file. I would like to get to know if it is possible to print out the content of a “RadChartView” control anyway.
Karim el Safadi
14 Answers, 1 is accepted
Thank you for writing.
Currently, RadChartView does not support printing as RadGridView and RadScheduler do, but you can still print the control as an image. Please, find attached an example where I paint the control in a Bitmap object and then print this object using a helper class which implements the IPrintable interface.
I hope this will be useful. Should you have further questions, I would be glad to help.
All the best,
Ivan Petrov
the Telerik team
I've used Your code but, the data that is presented in the RadPrintDocument isn't sent to the printer. It loads/shows the graph correctly but It does not send it to the printer.
What's missing me?
Thank you.
Best regards,
Luís Maurício
Thank you for writing.
There are several things to check out in this situation - your printer connection, drivers, supplies (ink, paper). Try printing a document from another application (e.g. Office Word). Try printing a RadGridView/RadScheduler. In the print dialog check whether you have selected the right printer. If you are trying to print to a file check whether PrintToFile is allowed.
I hope this will help. Feel free to write back with any further questions.
Greetings,
Ivan Petrov
the Telerik team
returning null in GetSettingsDialog() seems to crash the Application (2012Q3SP1 newest Hotfix)
Regards
Erwin
Ideally, I would set the page to landscape and have some AutoFit to the page bounds.
Could you advise?
Thank you both for writing.
@Erwin
Returning null would crash the app if you click on the settings button of the print preview dialog. You should either disable/hide this button or you can provide a custom settings dialog which should inherit Form/RadForm.
@Matthew
I have attached a modified version of the project from my first post which scales the chart image to fit in the page bounds.
If you have further questions, I would be glad to help.
Kind regards,
Ivan Petrov
the Telerik team
for those following this thread:
To print out in Landscape mode, set the RadPrintDocument.Landscape Property to true.
I've also added a quick hack to try and disable the settings ToolBar Button.
Additionally I've extended the ChartPrinter Class to take and print a page title.
private
void
printButton_Click(
object
sender, EventArgs e)
{
RadPrintDocument document =
new
RadPrintDocument();
document.Landscape =
true
;
document.AssociatedObject =
new
ChartPrinter(
this
.usageChartView,
this
.Machine.PrintableName +
" - Software Usage"
);
RadPrintPreviewDialog dialog =
new
RadPrintPreviewDialog(document);
try
{
// try to disable the print settings button
dialog.ToolCommandBar.CommandBarElement.Rows[0].Strips[0].Items[1].Enabled =
false
;
}
catch
(Exception)
{
;
}
dialog.ShowDialog();
}
Regards
Erwin
The Chart is now scaling to the page nicely, however referring to the original post, when trying to print to the printer, there is an issue.
1. Load the Chart onto the document.
2. Click the [Print] command bar button.
3. Select the required printer.
4. Click [Print]
A dialog saying "Printing 1 of Document" appears, but no printing happens.
I have tested the printer by printing to it from other applications and it is working fine.
I guess the ChartPrinter IPrintable Implementation EndPrint() function should return true instead of false
According to the docs, EndPrint() returns false if the printing was cancelled.
public
bool
EndPrint(RadPrintDocument sender, PrinterEventArgs args)
{
// return false; -- suspected problem here
return
true
;
}
Regards
Erwin
Thank you for writing.
Indeed, the EndPrint method should return true. Thank you Erwin for that point.
@Matthew: If you are still experiencing issues, please write back with more information on the situation.
Regards,
Ivan Petrov
the Telerik team
Yes. Changed the return to True and it works a treat.
Thank you all!
@Matthew: I am glad we were able to resolve the issue and came out with a working solution that satisfies your needs.
@Erwin: Thank you for your cooperation. Your Telerik points have been updated.
If there are further questions that need clarification, do not hesitate to write again.
Greetings,
Ivan Petrov
the Telerik team
I am having the same trouble with the print settings button on the RadPrintPreviewDialog, a complete app crash:
Object not set to an instance of an object...
at Telerik.WinControls.UI.RadPrintPreviewDialog.OnShowPrintSettingsDialog()\r\n at Telerik.WinControls.UI.RadPrintPreviewDialog.buttonSettings_Click(Object sender, EventArgs e)\r\n at Telerik.WinControls.RadElement.OnMouseDown(MouseEventArgs e)\r\n at Telerik.WinControls.RadItem.OnMouseDown(MouseEventArgs e)\r\n at Telerik.WinControls.RadElement.OnCLREventsRise(RoutedEventArgs args)\r\n at Telerik.WinControls.RadElement.OnBubbleEvent(RadElement sender, RoutedEventArgs args)\r\n at
...
...
...
Erwin's code to disable the settings button worked, but I would like to know if there are any known reasons (and fixes) for the underlying cause?
We're using the 2014.2.715.20 versions, Windows 7 in a VS2013 IDE.
Thank you for writing.
RadChartView now supports this functionality out of the box and you do not need to use this sample project any more. Detailed information is available here: Printing.
Please let me know if there is something else I can help you with.
Regards,
Dimitar
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.