Contents
- Index
- Previous
- Next
PrintPreview method
Applies to
TProfGrid component
Declaration
function PrintPreview(AImage: TImage; APage: Integer): Integer;
Description
Prepares a print-preview image for the calling application and calculates the number of pages in the printout.
The method takes two parameters: a TImage component where the print preview is to be painted and the page number of printout to paint. The return value is the total amount of pages in the printout. A TImage passed to the PrintPreview method becomes automatically scaled according to the following algorithm: its width is preserved intact, while its height is adjusted according to the ratio (page height) / (page width). After the PrintPreview method was called, the image is 'playable' in the AImage component. For example, you can provide custom zooming feature in your application just multiplying both AImage.Width and AImage.Height by the same scaling factor.
Note: Unlike many other parameters of methods, the page numbers are not zero-based, i.e. the first page is page 1, not page 0.
Tip: The PrintPreview method may be used to get a page count without actually previewing the grid. For this purpose, provide nil as the first parameter of the method call. (In this case, the second parameter may be anything you want and will be just ignored)..
Example
The following example shows how to implement a simple form with print preview capabilities.
unit Unit1;
interface
uses
Forms, Controls, Grids, ProfGrid, StdCtrls, ToolWin, ComCtrls, Classes, ExtCtrls;
type
TForm1 = class(TForm)
ProfGrid1: TProfGrid;
Image1: TImage;
ToolBar1: TToolBar;
ButtonPreview: TButton;
ButtonNextPage: TButton;
ButtonPreviousPage: TButton;
procedure ButtonPreviewClick(Sender: TObject);
procedure ButtonNextPageClick(Sender: TObject);
procedure ButtonPreviousPageClick(Sender: TObject);
private
{ Private declarations }
CurrentPage: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ButtonPreviewClick(Sender: TObject);
begin
ButtonNextPage.Enabled := ProfGrid1.PrintPreview(Image1, 1) > 1;
CurrentPage := 1;
ButtonPreviousPage.Enabled := False;
end;
procedure TForm1.ButtonNextPageClick(Sender: TObject);
begin
Inc(CurrentPage);
ButtonNextPage.Enabled := ProfGrid1.PrintPreview(Image1, CurrentPage) > CurrentPage;
ButtonPreviousPage.Enabled := CurrentPage > 1;
end;
procedure TForm1.ButtonPreviousPageClick(Sender: TObject);
begin
Dec(CurrentPage);
ButtonNextPage.Enabled := ProfGrid1.PrintPreview(Image1, CurrentPage) > CurrentPage;
ButtonPreviousPage.Enabled := CurrentPage > 1;
end;
end.