Page 1 of 1
Print Preview and CBuilder

Posted:
November 11th, 2006, 10:23 pm
by tomas
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]

Posted:
November 12th, 2006, 10:48 am
by Johnny_Bit
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.
C++Builder and PrintPreview

Posted:
November 12th, 2006, 1:36 pm
by tomas
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

Posted:
November 12th, 2006, 4:56 pm
by Johnny_Bit
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.
Re: C++Builder and PrintPreview

Posted:
November 13th, 2006, 9:10 am
by Kambiz
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.
CBuilder

Posted:
November 13th, 2006, 12:08 pm
by tomas
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 ?

Posted:
November 13th, 2006, 2:42 pm
by Johnny_Bit
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.

Posted:
November 13th, 2006, 3:01 pm
by tomas
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;

Posted:
November 13th, 2006, 3:16 pm
by Kambiz
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;

Posted:
November 13th, 2006, 7:32 pm
by tomas
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.

Posted:
November 13th, 2006, 7:38 pm
by Kambiz
TPrintPreview offers low level printing functions, so you have to do everything by yourself.