How to add Print/Print Preview to my Diagram application in WinForms?
The following code sample shows how you can add Print and Print/Preview support to your Essential® Diagram application using the CreatePrintDocument Method:
[C#]
// Set up Print
private void Print() {
System.Drawing.Printing.PrintDocument printDoc = this.diagram1.CreatePrintDocument();
PrintDialog printDlg = new PrintDialog();
printDlg.Document = printDoc;
if (printDlg.ShowDialog(this) == DialogResult.OK) {
printDoc.Print();
}
}// Set up Print Preview
private void PrintPreview() {
System.Drawing.Printing.PrintDocument printDoc = this.diagram1.CreatePrintDocument();
PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog();
printPreviewDlg.Document = printDoc;
printPreviewDlg.ShowDialog(this);
}// Print Preview Button
private void printpreviewbutton_Click(object sender, System.EventArgs e) {
this.PrintPreview();
}// Print Button
private void printtbutton_Click(object sender, System.EventArgs e) {
this.Print();
}
[VB.NET]
' Set up Print
Private Sub Print()
Dim printDoc As System.Drawing.Printing.PrintDocument = Me.diagram1.CreatePrintDocument()
Dim printDlg As PrintDialog = New PrintDialog()
printDlg.Document = printDoc
If printDlg.ShowDialog(Me) = DialogResult.OK Then
printDoc.Print()
End If
End Sub' Set up Print Preview
Private Sub PrintPreview()
Dim printDoc As System.Drawing.Printing.PrintDocument = Me.diagram1.CreatePrintDocument()
Dim printPreviewDlg As PrintPreviewDialog = New PrintPreviewDialog()
printPreviewDlg.Document = printDoc
printPreviewDlg.ShowDialog(Me)
End Sub' Print Preview Button
Private Sub printpreviewbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.PrintPreview()
End Sub' Print Button
Private Sub printtbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Me.Print()
End Sub
Conclusion
I hope you enjoyed learning about how to add Print/Print Preview to your Diagram application in WinForms.
You can refer to the WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!