Using the C1FlexGrid Control > Saving, Loading, and Printing > Printing Grids |
Use the PrintGrid method to print the contents of the grid. The method has parameters that allow you to select the scaling mode, whether to display print/preview dialog boxes, set headers and footers, and so on.
The PrintParameters property exposes additional printing properties such as the font to use for headers and footers, and a .NET Framework PrintDocument object that can be used to select the printer, paper size and orientation, margins, and so on.
The code below uses the PrintParameters property to set up the page orientation, margins, header and footer fonts. Then it calls the PrintGrid method to display a print preview dialog window:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
' Get the grid's PrintDocument object. Dim pd As Printing.PrintDocument pd = _flex.PrintParameters.PrintDocument() ' Set up the page (landscape, 1.5" left margin). With pd.DefaultPageSettings .Landscape = True .Margins.Left = 150 End With ' Set up the header and footer fonts. _flex.PrintParameters.HeaderFont = New Font("Arial Black", 14, FontStyle.Bold) _flex.PrintParameters.FooterFont = New Font("Arial Narrow", 8, FontStyle.Italic) ' Preview the grid. _flex.PrintGrid("C1FlexGrid", C1.Win.C1FlexGrid.PrintGridFlags.FitToPageWidth + C1.Win.C1FlexGrid.PrintGridFlags.ShowPreviewDialog, "C1FlexGrid" + Chr(9) + Chr(9) + Format(DateTime.Now, "d"), Chr(9) + Chr(9) + "Page {0} of {1}") |
To write code in C#
C# |
Copy Code
|
---|---|
// Get the grid' s PrintDocument object. System.Drawing.Printing.PrintDocument pd = _flex.PrintParameters.PrintDocument; // Set up the page (landscape, 1.5" left margin). pd.DefaultPageSettings.Landscape = true; pd.DefaultPageSettings.Margins.Left = 150; // Set up the header and footer fonts. _flex.PrintParameters.HeaderFont = new Font("Arial Black", 14, FontStyle.Bold); _flex.PrintParameters.FooterFont = new Font("Arial Narrow", 8, FontStyle.Italic); // Preview the grid. _flex.PrintGrid("C1FlexGrid", PrintGridFlags.FitToPageWidth | PrintGridFlags.ShowPreviewDialog, "C1FlexGrid\t\t" + Microsoft.VisualBasic.Strings.Format(DateTime.Now, "d"), "\t\tPage {0} of {1}"); |