passing text to preview on a seperate form

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

passing text to preview on a seperate form

Postby azarroth » May 7th, 2003, 4:40 am

How would I pass text in a richedit component to the printpreview component on a seperate form?
azarroth
Active Member
Active Member
 
Posts: 9
Joined: May 7th, 2003, 4:38 am
Location: Wisconsin, USA

Postby Kambiz » May 8th, 2003, 7:16 pm

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: Select all
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: Select all
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: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
  Form2.PrintRichEdit(RichEdit1);
end;


Hope that it helps.

Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: Bing [Bot] and 34 guests

cron