VSFlexGrid Control > VSFlexGrid Properties, Events, and Methods > VSFlexGrid Methods > PrintGrid Method |
Prints the grid on the printer.
[form!]VSFlexGrid.PrintGrid [ DocName As String ], [ ShowDialog As Boolean ], [ Orientation As Integer ], [ MarginLR As Long ], [ MarginTB As Long ]
The parameters for the PrintGrid method are described below:
DocName As String (optional)
Contains the name of the document being printed. This string appears in the printer window's job list and is also used as a footer.
ShowDialog As Variant (optional, default value = False)
If set to True, a printer selection/setup dialog is displayed before the document start printing. The user can then select which printer to use, page orientation etc.
Orientation As Variant (optional, default value = printer default)
Set this parameter to 1 to print the grid in Portrait mode, or set it to 2 to print the grid in Landscape mode. The default setting, zero, uses the default printer orientation.
MarginLR As Variant (optional, default value = 1440)
Left and right margins, in twips. The margins must be equal. The default value, 1440, corresponds to a one-inch margin.
MarginTB As Variant (optional)
Top and bottom margins, in twips. The margins must be equal. The default value, 1440, corresponds to a one-inch margin.
The grid is printed using the same fonts used to display it on the screen, so to achieve best results, make sure the grid's Font property is set to a TrueType font (such as Arial, Times New Roman, Tahoma, or Verdana).
While printing the grid, the control fires the BeforePageBreak and GetHeaderRow events. These events allow you to control page breaks and setup repeating headers.
The PrintGrid method prints the entire grid, possibly spilling across and down to new pages. To print only a part of the grid, hide to rows and columns you don't want to print, call the PrintGrid method, and restore the hidden rows and columns when you are done.
The code below shows how you can do this:
Private Sub PrintSelection(fg As VSFlexGrid, Row1&, Col1&, Row2&, Col2&)
' save current settings
Dim hl%, tr&, lc&, rd%
hl = fg.HighLight: tr = fg.TopRow: lc = fg.LeftCol: rd = fg.Redraw
fg.HighLight = 0
fg.Redraw = flexRDNone
' hide non-selected rows and columns
Dim i&
For i = fg.FixedRows To fg.Rows – 1
If i < Row1 Or i > Row2 Then fg.RowHidden(i) = True
Next
For i = fg.FixedCols To fg.Cols – 1
If i < Col1 Or i > Col2 Then fg.ColHidden(i) = True
Next
' scroll to top left corner
fg.TopRow = fg.FixedRows
fg.LeftCol = fg.FixedCols
' print visible area
fg.PrintGrid
' restore control
fg.RowHidden(-1) = False
fg.ColHidden(-1) = False
fg.TopRow = tr: fg.LeftCol = lc: fg.HighLight = hl
fg.Redraw = rd
End Sub