Printing

Support to print the data displayed in the EditControl by using the Print function. It also provides support to display print preview window by calling the PrintPreview function.

// Invoke the print dialog.

this.editControl1.Print();
' Invoke the print dialog.

Me.editControl1.Print()

Print dialog in syntax editor

In brief, the printing functionality of the EditControl supports the following features:

  • Print preview
  • Custom header and footer text
  • Document name
  • Page numbers
  • Color printing to preserve syntax highlighting
  • Selected text printing
  • Line numbers
  • Printing a specific page or set of pages
  • Printing entire document
  • Creating a printer document
  • Current page printing
  • Printer dialog

Use the PrintPreview function to view the content of the EditControl before printing it.

// View the contents of the EditControl before printing.

this.editControl1.PrintPreview();
' View the contents of the EditControl before printing.

Me.editControl1.PrintPreview()

Print preview of content in syntax editor

Specifying printing options

The EditControl provides various printing option like Visual Studio Code Editor. By using the PrintCurrentPage function, you can print the current page in the EditControl.

Functions Description

PrintCurrentPage

Prints the current page on the default printer.

PrintNoDialog

Prints the entire document on the default printer.

PrintSelection

Prints the selected area on the default printer.

PrintPages

Prints the pages in the specified range.
// Print the current page.

this.editControl1.PrintCurrentPage();

// Print the entire document.

this.editControl1.PrintNoDialog();

// Print the selected area.

this.editControl1.PrintPages(1, 10);

// Print the pages in the specified range.

this.editControl1.PrintSelection();
' Print the current page.

Me.editControl1.PrintCurrentPage()

' Print the entire document.

Me.editControl1.PrintNoDialog()

' Print the selected area.

Me.editControl1.PrintPages(1, 10)

' Print the pages in the specified range.

Me.editControl1.PrintSelection()

Provides a way to display additional content on the top (header) or bottom (footer) of the page while printing. These functionalities can be enabled or disabled by setting the PageHeaderAndFooterVisible property.

Printing document name and page number

The EditControl allows you to specify the desired text in the header and footer by handling the PrintHeader and PrintFooter events. The default text in the header and footer is the fully qualified path of the file including the file name and page number respectively. The PrintDocumentName and PrintPageNumber properties are used to enable or disable the name of the document and page number while printing.

private void editControl1_PrintHeader(object sender, Syncfusion.Windows.Forms.Edit.PrintHeadlineEventArgs e)
{

// Set the desired text in the header. The default text in the header is the full path and the name of the file.

e.Text = "This is the header";

}

private void editControl1_PrintFooter(object sender, Syncfusion.Windows.Forms.Edit.PrintHeadlineEventArgs e)
{

// Set desired text in the footer. The default text in the footer is the page number.

e.Text = "This is the footer";

}
Private Sub editControl1_PrintHeader(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Edit.PrintHeadlineEventArgs) Handles EditControl1.PrintHeader

' Set the desired text in the header. The default text in the header is the full path and the name of the file.

e.Text = "This is the header"

End Sub 

'editControl1_PrintHeader

Private Sub editControl1_PrintFooter(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Edit.PrintHeadlineEventArgs) Handles EditControl1.PrintFooter

' Set desired text in the footer. The default text in the footer is the page number.

e.Text = "This is the footer"

End Sub

The following image shows a typical page with a header and footer in Print Preview mode.

Print preview of content with header and footer in syntax editor

Show or hide page border

The PageBorder can be shown or hidden while printing the document. The SetPageBorder function is used to display page borders for the EditControl. You can also hide the page borders by using the RemovePageBorder of the EditControl.

// Set the page border. 

this.editControl1.SetPageBorder(Syncfusion.Windows.Forms.Edit.Enums.FrameBorderStyle.DashDot, Color.Red, Syncfusion.Windows.Forms.Edit.Enums.BorderWeight.Bold);

// Remove the page border.

this.editControl1.RemovePageBorder();
' Set the page border. 

Me.editControl1.SetPageBorder(Syncfusion.Windows.Forms.Edit.Enums.FrameBorderStyle.DashDot, Color.Red, Syncfusion.Windows.Forms.Edit.Enums.BorderWeight.Bold)

' Remove the page border.

Me.editControl1.RemovePageBorder()

NOTE

Refer to the following sample link that demonstrates the Printing functionalities in the EditControl:
C:\Users\<User>\AppData\Syncfusion\EssentialStudio\Version Number\Windows\Edit.Windows\Samples\Printing