DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

passing text to preview on a seperate form

 
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
azarroth
Member


Joined: 07 May 2003
Posts: 9
Location: Wisconsin, USA

PostPosted: 07/05/03 04:40    Post subject: passing text to preview on a seperate form Reply with quote

How would I pass text in a richedit component to the printpreview component on a seperate form?
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 206

PostPosted: 08/05/03 19:16    Post subject: Reply with quote

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
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group