Sign in Join
Wiki copytemporary

GridPrinter: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## About
22
3-<figure>
4-<img src="GridPrinter_v0.2.0.png" title="GridPrinter" />
5-<figcaption>GridPrinter</figcaption>
6-</figure>
3+![](/wiki-images/0/08/GridPrinter_v0.2.0.png)
74
8-<b>`TGridPrinter`</b> is a component to simplify printing of string grids or other descendants of TCustomGrid. It is bundled together with a ready-made print preview dialog, <b>`TGridPrintPreviewDialog`</b>, as well as standard actions to trigger printing or to show the preview dialog without writing a single line of code.
5+`TGridPrinter` is a component to simplify printing of string grids or other descendants of TCustomGrid. It is bundled together with a ready-made print preview dialog, `TGridPrintPreviewDialog`, as well as standard actions to trigger printing or to show the preview dialog without writing a single line of code.
96
107Author: Werner Pamler.
118
129License: Modified LGPL-2 (with linking exception, like Lazarus LCL).
1310
1411## Download and Installation
1512
1613### Release version
1714
1815The package is made available for installation by the Online-Package-Manager. Additionally, a zip file with the most recent release version can be found at [Lazarus CCR at SourceForge](https://sourceforge.net/projects/lazarus-ccr/files/GridPrinter/); unzip the file into any folder; load the file *gridprinterpkg.lpk* into Lazarus and click *Use* \> *Install*.
1916
2017### Development version
2118
2219The current development version is hosted at [Lazarus CCR](https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/gridprinter/). Use SVN to check it out, or download the zipped snapshot from this page. Install by loading the *gridprinterpkg.lpk* package file into Lazarus and clicking *Use* \> *Install*.
2320
2421## Getting Started
2522
2623#### How can I print a StringGrid?
2724
2825Nothing easier when you have the GridPrinter package...
2926
3027- Drop a `TGridPrinter` component on the form.
3128- Link its `Grid` property to the StringGrid that you want to print.
3229- In the `OnClick` handler of the button or menu item that is supposed to start the print-out, call the `Print` method of the `GridPrinter`. That's all.
3330
3431``` Pascal
3532procedure TForm1.PrintButtonClick(Sender: TObject);
3633begin
3734 GridPrinter1.Print;
3835end;
3936```
4037
4138#### How can I see a preview of the printout before the printer starts to waste paper?
4239
4340- Drop also a `TGridPrintPreviewDialog` on the form.
4441- Links its `GridPrinter` property to the GridPrinter instance that you had added in the previous exercise.
4542- In the `OnClick` handler of the button or menu item that is supposed to show the preview, call the `Execute` method of the `GridPrintPreviewDialog`.
4643- In the preview dialog you can scroll through the pages, zoom to various levels, change page orientation, adjust the page margins by dragging with the mouse, or add a header and/or footer. Of course, you can also print here, too.
4744
4845``` Pascal
4946procedure TForm1.PrintPreviewButtonClick(Sender: TObject);
5047begin
5148 GridPrintPreviewDialog1.Execute;
5249end;
5350```
5451
5552#### I have several printers and want to make sure that the print-out goes to the right one
5653
5754`TGridPrinter` has a property `ShowPrintDialog` which controls whether a print dialog should be displayed before printing starts. The kind of dialog is determined by the following options:
5855
5956- `gpdNone`: no print dialog
6057- `gpdPageSetup`: shows a `TPageSetupDialog`. Here you can select the paper size and set page orientation as well as page margins.
6158- `gpdPrintDialog`: shows a `TPrintDialog` where you can select the printer, the number of copies and the range of printed pages.
6259- `gpdPrinterSetup`: shows `TPrinterSetupDialog`. Here you can select the printer, the paper size and the page orientation.
6360
6461#### Can individual cell formatting by the OnPrepareCanvas event be applied to the printout?
6562
6663Yes. The `TGridPrinter` fires an `OnPrepareCanvas` event, too. Both even can share the same event handler. You only should be careful to use the correct `Canvas` when handling the event: When the `Sender` of the event is the grid, you must refer to the grid's `Canvas`, and when the `Sender` is the `GridPrinter` you must use that `Canvas` exposed by the `GridPrinter`; during printing this is the printer's `Canvas`, and when the preview is painted it is the `Canvas` of a temporary `TBitmap`.
6764
6865Let's assume that your `OnPrepareCanvas` handler is supposed to paint the column title in bold type face. This could be done by the following code. The procedure must be assigned to the `OnPrepareCanvas` of both grid and `GridPrinter`.
6966
7067``` Pascal
7168procedure TForm1.PrepareCanvasHandler(Sender: TObject; ACol, ARow: Integer; AState: TGridDrawState);
7269var
7370 lCanvas: TCanvas;
7471begin
7572 if Sender = StringGrid1 then
7673 lCanvas := StringGrid1.Canvas
7774 else
7875 if Sender = GridPrinter1 then
7976 lCanvas := GridPrinter1.Canvas
8077 else
8178 raise Exception.Create('Unknown sender of OnPrepareCanvas.');
8279
8380 if ARow < StringGrid1.FixedRows then
8481 lCanvas.Font.Style := [fsBold];
8582end;
8683```
8784
8885#### Can I print a DBGrid?
8986
9087Yes, but it requires a bit more work than just connecting it to the `Grid` property of the `GridPrinter`. A `DBGrid` displays data from a `TDataset`, but it keeps only a small number of records. But you usually want to print the entire dataset, rather than just the section loaded into the `DBGrid`.
9188
9289At first we must tell the `GridPrinter` how many rows it will have to print. This can be done by providing a handler for the event `OnGetRowCount` in which we pass the dataset's `RecordCount` value to the provided parameter. Note that the title row must be included here. Note also that the `RecordCount` property often is only correct after the dataset pointer has been moved to the last record and back to the first record.
9390
9491``` Pascal
9592procedure TForm1.GridPrinter1GetRowCount(Sender: TObject; AGrid: TCustomGrid;
9693 var ARowCount: Integer);
9794var
9895 dbGrid: TDBGrid;
9996begin
10097 dbGrid := AGrid as TDBGrid;
10198 dbGrid.Datasource.Dataset.Last;
10299 dbGrid.Datasource.Dataset.First;
103100 ARowCount := dbGrid.Datasource.Dataset.RecordCount + 1; // we must 1 for the header row
104101end;
105102```
106103
107104In order to provide the cell texts for the GridPrinter we must write a handler for the `OnGetCellText` event which is fired whenever the GridPrinter needs any cell text. We will return to this in a minute. We must first clarify the process flow. The easiest way to get the cell texts is by iterating over the entire dataset. Provide a handler for the `OnBeforePrint` event which moves the dataset to its first record:
108105
109106``` Pascal
110107procedure TForm1.GridPrinter1BeforePrint(Sender: TObject);
111108begin
112109 DBGrid1.DataSource.Dataset.First;
113110end;
114111```
115112
116113Another event, `OnNewLine` fires when the `GridPrinter` has finished printing a line and wants to proceed with the next one. This means we must advance the dataset to its next record. However, if a printed line extends over several pages we must be able to return to this record for completing its printout on the next page. Generally this must be handled by setting bookmarks - please see the example *dbgrid2* in the `GridPrinter` installation folder for details. For some flat-file databases such as *dBase*, *BufDataset* etc. there is a simpler way by using the `RecNo` property of the dataset. This is a running number for each record starting at 1 with the first record. So, in the `OnNewLine` event we simply set the dataset's `RecNo` to the row parameter passed to the event:
117114
118115``` Pascal
119116procedure TForm1.GridPrinter1NewLine(Sender: TObject; AGrid: TCustomGrid;
120117 ARow: Integer);
121118var
122119 dbGrid: TDBGrid;
123120begin
124121 dbGrid := AGrid as TDBGrid;
125122 BufDataset1.RecNo := ARow; // RecNo starts at 1. ARow starts at 1, too, since we display the header row
126123end;
127124```
128125
129126Then, within each row, the `GridPrinter` proceeds from grid column to grid column. In order to extract the cell text, we determine the column `col` from the `ACol` parameter of the `OnGetCellText`event and thus have access to the dataset field in that column (`col.Field`). Finally, we can query the cell text by calling the field's `AsString` method. Special handling is required for the very first row (`ARow = 0`) which corresponds to the grid titles:
130127
131128``` Pascal
132129procedure TForm1.GridPrinter1GetCellText(Sender: TObject; AGrid: TCustomGrid;
133130 ACol, ARow: Integer; var AText: String);
134131var
135132 dbGrid: TDBGrid;
136133 col: TColumn;
137134 colOffs: Integer;
138135begin
139136 AText := '';
140137
141138 dbGrid := AGrid as TDBGrid;
142139
143140 if (dgIndicator in dbGrid.Options) then
144141 colOffs := 1
145142 else
146143 colOffs := 0;
147144
148145 if ACol < colOffs then
149146 exit;
150147
151148 col := dbGrid.Columns[ACol - colOffs];
152149
153150 if (ARow = 0) then
154151 AText := col.FieldName
155152 else
156153 AText := col.Field.AsString;
157154end;
158155```
159156
160157As already mentioned, there are `DBGrid` sample projects in the `GridPrinter` installation to demonstrate the steps for `DBGrid` printing.
161158
162159#### How can I print a page number?
163160
164161You can print a page number at the top or bottom of every page by activating the header or footer of the `GridPrinter`. For this you select the `Header` (or `Footer` property and switch is `Visible` property to `true`. Then you enter the header (or footer) text in the property `Text`. In order to print the page number use for it the symbol `$PAGE` which is replaced by the number of the currently printed page. Note that the header/footer text consists of a left-aligned, centered and right-aligned part separated by a `'|'` character. So, if you want the page number to be centered the `Text` should be `'|$PAGE|'`, and if you want to include the total page count you could use '\|\$PAGE of \$PAGECOUNT\|'. Learn about the other symbols in the documentation section below.
165162
166163## Documentation
167164
168165### TGridPrinter
169166
170167#### Public methods
171168
172169- `function CreatePreviewBitmap(APageNo, APercentage: Integer): TBitmap` -- Creates the preview bitmap for the printout of the specified page. The bitmap is scaled by the given percentage relative to the original pager size (100).
173170- `function GetCellText(ACol, ARow: Integer): String` -- Returns the text to be printed for the grid cell at the given row and column indices.
174171- `procedure Print` -- Prints the grid. **Main method of the component**.
175172- `procedure ScaleToPages(NumHor, NumVert: Integer)` -- Scales the printout such that it fits on `NumHor` pages horizontally and `NumVert` pages vertically. When `NumHorPages` is 0 (or smaller) only the height is scaled according to `NumVert`. Similarly when `NumVert` is 0 (or smaller).
176173- `function ScaleX(AValue: Integer): Integer` -- General scaling function for conversion of horizontal screen pixels to pixels on the printer or the preview bitmap.
177174- `function ScaleY(AValue: Integer): Integer` -- General scaling function for conversion of vertical screen pixels to pixels on the printer or the preview bitmap.
178175- `procedure UpdatePreview` -- Fires the event `OnUpdatePreview` if the `GridPrinter` is in preview mode.
179176
180177#### Public properties
181178
182179- `Canvas: TCanvas` (read-only) -- Canvas currently used by the `GridPrinter`. This is either the printer canvas or the canvas of the preview bitmap sent to the `TGridPrintPreview` component.
183180- `ColCount: Integer` (read-only) -- Number of columns to be printed (including fixed columns).
184181- `ColWidth[AIndex: Integer]: Double` (read-only) -- Width of the specified column, given in pixels of the current output device (printer or preview bitmap).
185182- `FooterMargin: Integer` (read-only) -- Distance of the footer bottom from the page bottom, in pixels of the current output device.
186183- `HeaderMargin: Integer` (read-only) -- Distance of the header top from the page top, in pixels of the current output device.
187184- `PageHeight: Integer` (read-only) -- Height of the page, in pixels of the current output device.
188185- `PageWidth: Integer` (read-only) -- Width of the page, in pixels of the current output device.
189186- `PageRect: TRect` (read-only) -- Rectangle on the page, in pixels of the current output device, available for printing the grid. In other words: size of the page with margins subtracted.
190187- `PixelsPerInchX: Integer` (read-only) -- Pixel density of the current output device, in horizontal direction.
191188- `PixelsPerInchY: Integer` (read-only) -- Pixel density of the current output device, in vertical direction.
192189- `Padding: Integer` (read-only) -- Distance, in pixels of the current output device, between cell text and cell border.
193190- `PageCount: Integer` (read-only) -- Total number of pages to be printed.
194191- `PrintPageNumber: Integer` (read-only) -- Number of the page which is currently printed. Pages numbers begin with `1`.
195192- `PrintScaleToNumHorPages: Integer` -- The `PrintScalingFactor` is adjusted such that this number of pages fits onto a single sheet of paper horizontally.
196193- `PrintScaleToNumVertPages: Integer` -- The `PrintScalingFactor` is adjusted such that this number of pages fits onto a single sheet of paper vertically.
197194- `PrintScalingMode: TGridPrnScalingMode` -- Determines how the print output is scaled.
198195 - `smManual` -- The current value of the `PrintScalingFactor` is applied.
199196 - `smFitToWidth` -- The `PrintScalingFactor` is adjusted so that the number of pages given by `PrintScaleToNumVertPages` fit onto a single page vertically.
200197 - `smsmFitToHeight` -- The `PrintScalingFactor` is adjusted so that the number of pages given by `PrintScaleToNumHorPages` fit onto a single page horizontally.
201198 - `smFitAll` -- The `PrintScalingFactor` is adjusted so that the entire grid fits onto a single page.
202199- `RowCount: Integer` (read-only) -- Number of rows to be printed (including fixed rows).
203200- `RowHeight[AIndex: Integer]: Double` (read-only) -- Height of the specified row, given in pixels of the current output device.
204201
205202#### Published properties and events
206203
207204**Properties**
208205
209206- `Grid: TCustomGrid` -- Links to the grid to be printed. Ideally, this should be a `TStringGrid`, but other descendants of `TCustomGrid` can be printed as well when the appropriate event handlers are provided.
210207- `BorderLineColor: TColor` -- Line color of the outer border of the printed grid.
211208- `BorderLineWidth: Double` -- Line width of the outer border of the printed grid, in millimeters. If not positive, the scaled value of the grid's `GridLineWidth` is used.
212209- `FileName: String` -- Has no functional use inside the `GridPrinter`. But indicates the name of the file which is printed, if applicable. The filename is displayed in the header or footer of the printout/preview where it is used to replace the symbols `$FULL_FILENAME`, `$FILENAME`, `$PATH` in the header/footer `Text`.
213210- `FixedLineColor: TColor` -- Line color of the dividing line between fixed and normal cells in the printout/preview.
214211- `FixedLineWidth: Double` -- Line width of the dividing line between fixed and normal cells in the printout/preview, in millimeters. If not positive, the scaled value of the grid's `GridLineWidth` is used.
215212- `Footer: TGridPrnHeaderFooter` -- Parameters for printing a footer at the bottom of each page. See TGridPrnHeaderFooter.
216213- `FromPage: Integer` -- Defines the first page to be printed. Any value less than 1 is interpreted as "first page".
217214- `GridLineColor: TColor` -- Color of the inner grid lines.
218215- `GridLineWidth: Double` -- Line width of the inner grid lines, in millimeters. If not positive, the scaled value of the grid's `GridLineWidth` is used.
219216- `Header: TGridPrnHeaderFooter` -- Parameters for printing a header at the top of each page. See TGridPrnHeaderFooter
220217- `Margins: TGridPrnMargins` -- Defines page and header/footer margins, in millimeters. See TGridPrnMargins.
221218- `Monochrome: Boolean` -- Prints the grid only with black color.
222219- `Options: TGridPrnOptions` -- Options for fine-tuning the printout:
223220 - `gpoCenterHor` -- Centers the printed table on the page horizontally.
224221 - `gpoCenterVert` -- Centers the printed table on the page vertically.
225222 - `gpoHorGridLines` -- Overrides the corresponding grid option and can be used to show/hide horizontal grid lines between the printed rows.
226223 - `gpoVertGridLines` -- Overrides the corresponding grid option and can be used to show/hide vertical grid lines between the printed columns.
227224 - `gpoFixedHorGridLines` -- Can be used to show/hide horizontal grid lines between the fixed cells.
228225 - `gpoFixedVertGridLines` -- Can be used to show/hide vertical grid lines between the fixed cells.
229226 - `gpoHeaderBorderLines` -- Can be used to show/hide dividing lines between the fixed and normal cells.
230227 - `gpoOuterBorderLines` -- Can be used to show/hide outer lines around the grid.
231228- `Orientation: TPrinterOrientation` -- Defines the page orientation: `poPortrait`, `poLandscape`, `poReverseLandscape`, `poReversePortrait` (declared in the *Printers* unit).
232229- `PrintOrder: TGridPrnOrder` -- Large grids are wrapped into several pages. This property defines whether rows (`poRowsFirst`) or columns (`poColsFirst`) will be completed first.
233230- `PrintScaleFactor: Double` -- Scaling factor for the printout. Default: `1.0`. Call the method `ScaleToPages()` if you want to adjust the `PrintScaleFactor` such that the entire printout fits on a given number of pages.
234231- `ShowPrintDialog: TGridPrnDialog` -- Determines whether one of the Lazarus print dialogs should be shown before printing begins: `gpdNone`, `gpdPageSetup`, `gpdPrintDialog`, `gpdPrinterSetup`.
235232- `ToPage: Integer` -- Defines the last page to be printed. Any value larger than the real page count prints to the last page.
236233
237234**Events**
238235
239236- `OnAfterPrint` -- Fires when printing is finished.
240237- `OnBeforePrint` -- Fires before printing begins. The printer has not yet received its `BeginDoc` command.
241238- `OnGetCellText` -- Whenever the `GridPrinter` needs to know the text in a specific cell it sends this event. The text to be printed can be passed in a parameter. This way non-standard grid which have different cell technology can be printed as well.
242239- `OnGetRowCount` -- In this event the application can tell the `GridPrinter` the number of rows to be printed. This is useful for printing a `DBGrid` which holds only a small portion of all rows of a dataset.
243240- `OnGetColCount` -- Similar to `OnGetRowCount`, just for columns, rather than rows.
244241- `OnLinePrinted` -- Fires when the `GridPrinter` has finished printing a specific line.
245242- `OnNewLine` -- Fires when the `GridPrinter` starts printing a new line of cells.
246243- `OnNewPage` -- Fires when the `GridPrinter` begins a new page.
247244- `OnPrepareCanvas` -- Similar to the equally-named event of the grid. When the canvas for printing a cell has been prepared the user has the opportunity here to override the selection of colors, fonts, alignments etc. The handler can be shared between grid and `GridPrinter`, it only must be guaranteed that the correct canvas is used in the code.
248245- `OnPrintCell` -- When this event has a handler it completely replaces the built-in code for printing a cell. Can be used for printing very specific grids.
249246- `OnUpdatePreview` -- When the `GridPrinter` runs in preview mode the application can be notified, for example, when some parameter has been changed and the preview can repaint itself.
250247
251248##### TGridPrnHeaderFooter
252249
253250This is the class of the header and footer lines which can be printed at the top and bottom of each page.
254251
255252**Published properties**
256253
257254- `Font: TFont` -- Font used for printing the header/footer.
258255- `LineColor: TColor` -- Color of the dividing line printed below the header/above the footer.
259256- `LineWidth: Double` -- Line width of the dividing line printed below the header/above the footer, in millimeters.
260257- `SectionSeparator: String` -- The header/footer text can consist of a left-aligned, centered, and a right-aligned part, all specified together in the `Text`property. Defines the separator character or string between these three sections, default: `'|'`.
261258- `ShowLine: Boolean` -- Shows/hides the dividing line printed below the header/above the footer.
262259- `Text: String` -- Contains the text to be displayed in the header/footer. It can consist of up to three sections, separated by the `SectionSeparator`, which are printed at the left, in the center or at the right end of the header/footer. Moreover, the `Text` can contain the following symbols which are replaced during printing by the current values:
263260 - `$DATE` -- Replaced by current date.
264261 - `$PAGECOUNT` -- Total number of pages to be printed.
265262 - `$PAGE` -- Number of the currently printed page. First page number is `1`.
266263 - `$FULL_FILENAME` -- Is replaced by the full path of the `FileName` property of the `GridPrinter`.
267264 - `$FILENAME` -- Is replaced by the `FileName` property of the `GridPrinter` after removal of the file path.
268265 - `$PATH` -- Is replaced by the path to the `FileName` property of the `GridPrinter`.
269266 - `$TIME` -- Replaced by current time.
270267- `Visible: Boolean` -- Shows/hides the header/footer.
271268
272269**Public properties**
273270
274271- `ProcessedText[AIndex: TGridPrnHeaderFooterSection]: String` where `TGridPrnHeaderFooterSection = (hfsLeft, hfsCenter, hfsRight)` -- returns the header/footer text in the specified section after replacement of the symbols.
275272- `SectionText[AIndex: TGridPrnHeaderFooterSection]: String` where `TGridPrnHeaderFooterSection = (hfsLeft, hfsCenter, hfsRight)` -- returns the specified section `Text`.
276273
277274##### TGridPrnMargins
278275
279276This class collects the parameters for the page margins:
280277
281278**Published properties**
282279
283280- `Left: Double` -- Left margin, in millimeters.
284281- `Top: Double` -- Top margin, in millimeters.
285282- `Right: Double` -- Right margin, in millimeters.
286283- `Bottom: Double` -- Bottom margin, in millimeters.
287284- `Header: Double` -- Margin to the top of the header, in millimeters. Note that it is not checked that the header does not overlap with the grid.
288285- `Footer: Double` -- Margin to the bottom of the footer, in millimeters. Note that it is not checked that the footer does not overlap with the grid.
289286
290287### TGridPrintPreviewDialog
291288
292289In unit *GridPrnPreviewDlg*.
293290
294291#### Public methods
295292
296293- `procedure Execute` -- Displays the preview form **(Main method of the component)**.
297294
298295#### Published properties
299296
300297- `FormParams: TGridPrintPreviewFormParams` -- Parameters which define size and position of the preview form. See TGridPrintPreviewFormParams.
301298- `GridPrinter: TGridPrinter` -- Links to the `TGridPrinter` instance which actually performs the printing.
302299- `Options: TGridPrintPreviewOptions` -- Controls the options the user has to modify the preview (declared in unit *GridPrnPreviewForm*:
303300 - `ppoNavigationBtns` -- Enables/disables page navigation in the preview.
304301 - `ppoNavigationEdit` -- Shows/hides the edit control in the preview toolbar with which the user can navigate to a specific page of the preview.
305302 - `ppoZoomBtns` -- Enables/disables zooming in the preview.
306303 - `ppoPageOrientationBtns` -- Enables/disables selection of page orientation.
307304 - `ppoMarginsBtn` -- Enables/disables page margin selection in the preview.
308305 - `ppoHeaderFooterBtn` -- Enables/disables the possibility to set up the header and footer in a dialog.
309306 - `ppoPrintOrderBtns` -- Enables/disables the possibility to define the order of pages when the entire print-out does not fit onto a single page of paper.
310307 - `ppoCenterBtns` -- Shows/hides the buttons to center the grid on the printed page.
311308 - `ppoScalePrinterBtn` -- Shows/hides the button to scale the printer output manually or to force a given count of pages onto a single sheet.
312309 - `ppoPageSetupBtn` -- Shows/hides a toolbar button with a dropdown menu containing options to control the page layout (page orientation, margin selection, etc).
313310 - `ppoPageNumberInfo` -- Shows/hides the display of page number and total page count in the preview form.
314311 - `ppoZoomLevelInfo` -- Shows/hides the display of the preview zoom level (percentage) in the preview form.
315312- `Zoom: Integer` -- Scaling factor, in percent, applied when the preview bitmap is displayed in the preview form. Default: `100`.
316313- `ZoomMode: TGridPrintPreviewZoomMode` - Determines how the preview bitmap is scaled by means of the `Zoom` scaling factor:
317314 - `zmCustom` -- The current value of the `Zoom` factor is applied directly.
318315 - `zmFitWidth` -- The `Zoom` factor is adjusted so that the page fits horizontally into the preview window.
319316 - `zmFitHeight` -- The `Zoom` factor is adjusted such that the page fits vertically into the preview window.
320317
321318##### TGridPrintPreviewFormParams
322319
323320- `Left: Integer` -- Position of the left edge of the preview form on the screen, in screen pixels.
324321- `Top: Integer` -- Position of the top edge of the preview form on the screen, in screen pixels.
325322- `Width: Integer` -- Width of the preview form, in screen pixels.
326323- `Height: Integer` -- Height of the preview form, in screen pixels.
327324- `Position: TPosition` -- Standard LCL form position options overriding the other parameters in the `GridPrintPreviewFormParams`, e.g. `poMainFormCenter` or `poScreenCenter` to center the form over the mainform or on the screen, respectively.
328325
329326#### Functionality of the preview form
330327
331328The preview dialog contains a toolbar with a variety of buttons. By means of the `Options` of the `GridPrintPreviewDialog` it is possible to hide those buttons which are not needed.
332329
333330Here is a description of what the buttons can be used for:
334331
335332- ![](/wiki-images/9/9f/Gridprn_print.png) Sends the grid to the printer, as displayed by the preview.
336333- ![](/wiki-images/3/32/Gridprn_firstpage.png) Displays the first page of the preview.
337334- ![](/wiki-images/0/01/Gridprn_prevpage.png) Displays the previous page of the preview.
338335- ![](/wiki-images/d/d5/Gridprn_nextpage.png) Displays the next page of the preview.
339336- ![](/wiki-images/e/ea/Gridprn_lastpage.png) Displays the last page of the preview.
340337- ![](/wiki-images/0/07/Gridprn_zoomin.png) Enlarges the preview ("zoom in").
341338- ![](/wiki-images/1/1f/Gridprn_zoomout.png) Reduces the preview ("zoom out").
342339- ![](/wiki-images/8/88/Gridprn_zoom100.png) Original size of the preview page (100%).
343340- ![](/wiki-images/c/c8/Gridprn_zoomtowidth.png) Scales the preview image so that it fills the width of the preview window.
344341- ![](/wiki-images/9/9f/Gridprn_zoomtoheight.png) Scales the preview image so that it fills the height of the preview window.
345342- ![](/wiki-images/c/c2/Gridprn_portrait.png) Switches the page to portrait orientation.
346343- ![](/wiki-images/6/65/Gridprn_landscape.png) Switches the page to landscape orientation.
347344- ![](/wiki-images/1/14/Gridprn_headerfooter.png) Shows a dialog to set up the header and/or footer of the printout.
348345- ![](/wiki-images/9/9c/Gridprn_pagemargins.png) Displays the page margins as lines. Drag these lines to adjust the margins.
349346- ![](/wiki-images/5/58/Gridprn_rowsfirst.png) In case of large grids the rows are printed first before advancing to the next block of rows.
350347- ![](/wiki-images/f/fa/Gridprn_colsfirst.png) In case of large grids the columns are printed first before advancing to the next block of columns.
351348- ![](/wiki-images/c/c5/Gridprn_centerhor.png) Centers the grid on the printed page horizontally.
352349- ![](/wiki-images/8/8b/Gridprn_centervert.png) Centers the grid on the printed page vertically.
353350- ![](/wiki-images/b/bc/Gridprn_scaleprinter.png) Opens a dialog in which a scale factor for the printout can be defined. This way, for example, a large grid can be "squeezed" onto a single page.
354351- ![](/wiki-images/8/83/Gridprn_pagesetup.png) Opens a dropdown menu with a collection of the commandsabove. This is useful when not all buttons are shown on the toolbar.
355352
356353The icons displayed on these buttons are taken from the Lazarus general-purpose image collection provided by [Roland Hahn](https://www.rhsoft.de/).
357354
358355### GridPrinter Actions
359356
360357Unit *GridPrnActions* implements two standard actions for further simplification of usage
361358
362359#### TGridPrinterAction
363360
364361When its property `GridPrinter` is linked to a `TGridPrinter` instance and the action is linked to the `Action` property of a control a click on the control executes the `Print` method of the `GridPrinter` without any additional code.
365362
366363#### TGridPrintPreviewAction
367364
368365When its property `PreviewDialog` is linked to a `TGridPrintPreviewDialog` instance and the action is linked to the `Action` property of a control a click on the control runs the `Execute` method of the `GridPrintPreviewDialog` without any additional code.
369366
370367---
371368*From the Free Pascal wiki, page "GridPrinter", as it stood on 2022-12-14 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history