richmemo: print sample
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4060 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
72db518cb9
commit
5384089c5f
76
components/richmemo/samples/print/mainform.lfm
Normal file
76
components/richmemo/samples/print/mainform.lfm
Normal file
@ -0,0 +1,76 @@
|
||||
object Form1: TForm1
|
||||
Left = 387
|
||||
Height = 240
|
||||
Top = 148
|
||||
Width = 687
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 240
|
||||
ClientWidth = 687
|
||||
LCLVersion = '1.2.4.0'
|
||||
object RichMemo1: TRichMemo
|
||||
Left = 8
|
||||
Height = 178
|
||||
Top = 8
|
||||
Width = 663
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
HideSelection = False
|
||||
Lines.Strings = (
|
||||
'RichMemo1'
|
||||
)
|
||||
ScrollBars = ssAutoBoth
|
||||
TabOrder = 0
|
||||
ZoomFactor = 1
|
||||
end
|
||||
object Button1: TButton
|
||||
Left = 8
|
||||
Height = 25
|
||||
Top = 200
|
||||
Width = 75
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Print'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 1
|
||||
end
|
||||
object Button2: TButton
|
||||
Left = 596
|
||||
Height = 25
|
||||
Top = 200
|
||||
Width = 75
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Load RTF'
|
||||
OnClick = Button2Click
|
||||
TabOrder = 2
|
||||
end
|
||||
object Button3: TButton
|
||||
Left = 120
|
||||
Height = 25
|
||||
Top = 200
|
||||
Width = 107
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Printer'
|
||||
OnClick = Button3Click
|
||||
TabOrder = 3
|
||||
end
|
||||
object Button4: TButton
|
||||
Left = 240
|
||||
Height = 25
|
||||
Top = 200
|
||||
Width = 112
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Pages Setup'
|
||||
OnClick = Button4Click
|
||||
TabOrder = 4
|
||||
end
|
||||
object OpenDialog1: TOpenDialog
|
||||
left = 48
|
||||
top = 24
|
||||
end
|
||||
object PrinterSetupDialog1: TPrinterSetupDialog
|
||||
left = 152
|
||||
top = 24
|
||||
end
|
||||
object PageSetupDialog1: TPageSetupDialog
|
||||
left = 272
|
||||
top = 24
|
||||
end
|
||||
end
|
95
components/richmemo/samples/print/mainform.pas
Normal file
95
components/richmemo/samples/print/mainform.pas
Normal file
@ -0,0 +1,95 @@
|
||||
unit mainform;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs,
|
||||
Printers,
|
||||
StdCtrls, RichMemo, RichMemoUtils;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
Button3: TButton;
|
||||
Button4: TButton;
|
||||
OpenDialog1: TOpenDialog;
|
||||
PageSetupDialog1: TPageSetupDialog;
|
||||
PrinterSetupDialog1: TPrinterSetupDialog;
|
||||
RichMemo1: TRichMemo;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure Button3Click(Sender: TObject);
|
||||
procedure Button4Click(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog1.Execute then
|
||||
LoadRTFFile(RichMemo1, OpenDialog1.FileName);
|
||||
end;
|
||||
|
||||
|
||||
procedure PageSetupToMargins(pg: TPageSetupDialog; var p: TPrintParams);
|
||||
var
|
||||
md : Single; // modifies to tunr into inches
|
||||
pt : Single;
|
||||
begin
|
||||
if pg.Units=unMM then md:=0.254
|
||||
else md:=0.001;
|
||||
|
||||
p.Margins.Left:=pg.Margins.Left*md*72;
|
||||
p.Margins.Top:=pg.Margins.Top*md*72;
|
||||
p.Margins.Right:=-pg.Margins.Right*md*72;
|
||||
p.Margins.Bottom:=pg.Margins.Bottom*md*72;
|
||||
|
||||
writeln(p.Margins.Left:0:2);
|
||||
end;
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
var
|
||||
prm : TPrintParams;
|
||||
begin
|
||||
if not Assigned(Printer) then begin
|
||||
ShowMessage('No printer found.');
|
||||
Exit;
|
||||
end;
|
||||
InitPrintParams(prm);
|
||||
prm.SelStart:=RichMemo1.SelStart;
|
||||
prm.SelLength:=RichMemo1.SelLength;
|
||||
prm.Title:='Rich Memo Printing';
|
||||
PageSetupToMargins(PageSetupDialog1, prm);
|
||||
|
||||
RichMemo1.Print(prm);
|
||||
end;
|
||||
|
||||
procedure TForm1.Button3Click(Sender: TObject);
|
||||
begin
|
||||
PrinterSetupDialog1.Execute;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button4Click(Sender: TObject);
|
||||
begin
|
||||
PageSetupDialog1.Execute;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
87
components/richmemo/samples/print/project1.lpi
Normal file
87
components/richmemo/samples/print/project1.lpi
Normal file
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="project1"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="3">
|
||||
<Item1>
|
||||
<PackageName Value="Printer4Lazarus"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="richmemopackage"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item3>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="project1.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="project1"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="mainform"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="project1"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
21
components/richmemo/samples/print/project1.lpr
Normal file
21
components/richmemo/samples/print/project1.lpr
Normal file
@ -0,0 +1,21 @@
|
||||
program project1;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, printer4lazarus, mainform
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user