Print Preview and CBuilder

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

Print Preview and CBuilder

Postby tomas » November 11th, 2006, 10:23 pm

Has anybody experience with PrintPreview and CBuilder 6? I was trying to print some picture but my experiments resulted only in exception :-).
Code: Select all
TPrintDialog *PrintDialog1=new TPrintDialog(this);
PrintDialog1->MinPage=1;
PrintDialog1->MaxPage=1;
PrintDialog1->PrintRange= prAllPages;
PrintPreview1->BeginDoc();

PrintPreview1->Canvas->MoveTo(1,1);
PrintPreview1->Canvas->LineTo(100,100);
PrintPreview1->Canvas;
PrintPreview1->EndDoc();
delete PrintDialog1;

What´s wrong?

Thanks

Tom[/code]
tomas
Active Member
Active Member
 
Posts: 8
Joined: November 10th, 2006, 11:33 pm
Location: Czech republic

Postby Johnny_Bit » November 12th, 2006, 10:48 am

Dunno, but your code looks a bit weird, you actually creating new printdialog, then repainting preview... why don't you use existing dialog then try to repaint everything? check the demo for correct method of printing.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

C++Builder and PrintPreview

Postby tomas » November 12th, 2006, 1:36 pm

I wrote it not correct, so:
Code: Select all
TPrintPreview *PrintPreview1=new TPrintPreview(this);
...
PrintPreview1->BeginDoc();
PrintPreview1->Canvas->MoveTo(1,1);
PrintPreview1->Canvas->LineTo(100,100);
PrintPreview1->Canvas;
PrintPreview1->EndDoc();  //results in exception
...
delete PrintPreview1;

I did not find any cpp example included :-(. Could you write here a short example in C or send some link, please?? I don´t use Delphi...

Thanks
tomas
Active Member
Active Member
 
Posts: 8
Joined: November 10th, 2006, 11:33 pm
Location: Czech republic

Postby Johnny_Bit » November 12th, 2006, 4:56 pm

Hmm... that would be difficult since i work on linux for a long time, but i'll try.

First, don't bother dynamically create printpreview, drop it on for it would be much easier. So lets assume that and go on.

Code: Select all
...
TRect R;
...
PrintPreview1->BeginDoc();
R=PrintPreview1->PageBounds;
PrintPreview1->Canvas->MoveTo(R.Top, R.Left);
PrintPreview1->Canvas->LineTo(R.Top+100, R.Left+100);
PrintPreview1->EndDoc();
...


Besides, translating from c to delphi and vice-versa is quite simple... unless with records and objects, I don't even want to know that... records by dot, objects by arrow... damn.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Re: C++Builder and PrintPreview

Postby Kambiz » November 13th, 2006, 9:10 am

bayer wrote:I wrote it not correct, so:
Code: Select all
TPrintPreview *PrintPreview1=new TPrintPreview(this);
...
PrintPreview1->BeginDoc();
PrintPreview1->Canvas->MoveTo(1,1);
PrintPreview1->Canvas->LineTo(100,100);
PrintPreview1->Canvas;
PrintPreview1->EndDoc();  //results in exception
...
delete PrintPreview1;

I did not find any cpp example included :-(. Could you write here a short example in C or send some link, please?? I don´t use Delphi...

Thanks

The reason you get an exception is that your newly created PrintPreview has no Parent control.

You should follow Johnny_Bit's code as the right code.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

CBuilder

Postby tomas » November 13th, 2006, 12:08 pm

Thanks, a new command was added:

PrintPreview1->Parent=Form1;

How could I display print properties (page orientation, scale, page numbers) on the form? Only canvas with drawing was displayed. It is also necessary to set working units, drawing looks very small ?
tomas
Active Member
Active Member
 
Posts: 8
Joined: November 10th, 2006, 11:33 pm
Location: Czech republic

Postby Johnny_Bit » November 13th, 2006, 2:42 pm

well... since you put it that way, you could use ConvertXY method from preview unit. it allows you to convert between any units. there is a code in demo, that can be easily translated to something like this:
Code: Select all
...
TPoint conv;
...
conv=PrintPreviev1->ConvertXY(100, 100, mmLoMetric, PrintPreview1->Units); //100 in LoMetric=1cm
...
PrintPreview1->Canvas->LineTo(conv.X, conv.Y);


That would help.

To display Additional things, additional components were made, like TPaperPreview, TThumbnailPreview. Others are easily accessible from printing properties, and you should display them manually.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby tomas » November 13th, 2006, 3:01 pm

Thanks...

But threre is another problem. Preview was OK (component was resized to the whole window area), but no picture was printed.

...
PrintPreview1=new TPrintPreview(Form1);
PrintPreview1->Parent=Form1;
PrintPreview1->BeginDoc();
PrintPreview1->Canvas->MoveTo(0,0);
TPoint conv;
conv=PrintPreview1->ConvertXY(1000, 1000, mmLoMetric, PrintPreview1->Units); //100 in LoMetric=1cm
PrintPreview1->Canvas->LineTo(conv.x, conv.y);
PrintPreview1->Canvas;
PrintPreview1->PrintPages(1,2);
PrintPreview1->EndDoc();
delete PrintPreview1;
tomas
Active Member
Active Member
 
Posts: 8
Joined: November 10th, 2006, 11:33 pm
Location: Czech republic

Postby Kambiz » November 13th, 2006, 3:16 pm

I wonder why you create the control manually?

Anyway you have to call PrintPages method after EndDoc.

Also, you can tell PrintPreview to do not create preview and instead print the pages directly.

Code: Select all
PrintPreview1->DirectPrint := True;
PrintPreview1->BeginDoc();
PrintPreview1->Canvas->MoveTo(0,0);
TPoint conv;
conv=PrintPreview1->ConvertXY(1000, 1000, mmLoMetric, PrintPreview1->Units); //100 in LoMetric=1cm
PrintPreview1->Canvas->LineTo(conv.x, conv.y);
PrintPreview1->EndDoc();


By the way, what the reason of the following line in your code?

Code: Select all
PrintPreview1->Canvas;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm

Postby tomas » November 13th, 2006, 7:32 pm

Thanks.

>>> I wonder why you create the control manually?
You think new/delete construction? I tried to install and add dowloaded data as a new component to CBuilder, but I was not successful :-).

Very nice component... I used QReport, but this component is much better. Is there any possibility to draw a StrinGrid with grid lines? I could print cells and then draw lines, but maybe there is a better way.
tomas
Active Member
Active Member
 
Posts: 8
Joined: November 10th, 2006, 11:33 pm
Location: Czech republic

Postby Kambiz » November 13th, 2006, 7:38 pm

TPrintPreview offers low level printing functions, so you have to do everything by yourself.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2405
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron