source: PrintPreview/Demo/UFormMain.pas

Last change on this file was 455, checked in by chronos, 12 years ago
  • Modified: PrintPreview should use TVectorCanvas instead of raster TCanvas dependent on DPI of printer. But some font function as TextWidth and TextHeight cannot be easily implemented without use of OS API.
File size: 1.2 KB
Line 
1unit UFormMain;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
9 UPrintPreview;
10
11type
12
13 { TFormMain }
14
15 TFormMain = class(TForm)
16 ButtonPreview: TButton;
17 PrintPreview1: TPrintPreview;
18 procedure ButtonPreviewClick(Sender: TObject);
19 procedure PrintPreview1Print(Sender: TObject);
20 private
21 { private declarations }
22 public
23 { public declarations }
24 end;
25
26var
27 FormMain: TFormMain;
28
29implementation
30
31{$R *.lfm}
32
33{ TFormMain }
34
35procedure TFormMain.ButtonPreviewClick(Sender: TObject);
36begin
37 PrintPreview1.Execute;
38end;
39
40procedure TFormMain.PrintPreview1Print(Sender: TObject);
41begin
42 with PrintPreview1, Canvas do begin
43 Font.Name := 'Arial';
44 Font.Height := -Round(Font.PixelsPerInch / SizeDivider);
45 Font.Color := clBlack;
46 PageTitle := 'Print preview demo';
47 Line(MMToPixels(10), MMToPixels(10), MMToPixels(100), MMToPixels(100));
48 TextOut(MMToPixels(50), MMToPixels(100), 'Some simple text');
49 Font.Height := -Round(Font.PixelsPerInch / SizeDivider * 4);
50 TextOut(MMToPixels(100), MMToPixels(150), 'Big text');
51 end;
52end;
53
54end.
55
Note: See TracBrowser for help on using the repository browser.