Kambiz Administrator

Joined: 07 Mar 2003 Posts: 206
|
Posted: 08/05/03 19:16 Post subject: |
|
|
Actually there is no difference between using PrintPreview component in the same form or another form.
For example suppose you have two forms: TForm1 in unit1 and TForm2 (with PrintPreview) in unit2. You should add unit2 in uses clause of unit1 and after use a code like the following code to print the content of your RichEdit control:
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
R: TRect;
OneInch: Integer;
begin
Form2.Show;
with Form2.PrintPreview do
begin
OneInch := ConvertUnit(10, mmLoEnglish, Units);
SetRect(R, 0, 0, PaperWidth, PaperHeight);
InflateRect(R, -OneInch, -OneInch);
PaintRichText(R, RichEdit1, 0, nil);
end;
end; |
However, I suggest to add a public method to TForm2 and write your print code inside. For example the following code can be converted as follow:
| Code: | procedure TForm2.PrintRichEdit(RichEdit: TCustomRichEdit);
var
R: TRect;
OneInch: Integer;
begin
with PrintPreview do
begin
OneInch := ConvertUnit(10, mmLoEnglish, Units);
SetRect(R, 0, 0, PaperWidth, PaperHeight);
InflateRect(R, -OneInch, -OneInch);
PaintRichText(R, RichEdit, 0, nil);
end;
end; |
You can call the above function in the first unit as follow:
| Code: | procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
Form2.PrintRichEdit(RichEdit1);
end; |
Hope that it helps.
Kambiz |
|