Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing chart from dbchart ....:( 1

Status
Not open for further replies.

xor2

Programmer
Mar 24, 2005
22
HI,
This is the procedure which prints my chart:

var
PrintRct : tRect;
OldPOrient : tPrinterOrientation;
begin
if printersetupdialog1.Execute then begin
OldPOrient := Printer.Orientation;
PrintRct.Top := 0;
PrintRct.Left := 0;
PrintRct.Bottom := Printer.PageWidth-1;
PrintRct.Right := Printer.PageHeight-1;
with Chart do begin
Printer.Orientation := poLandScape;
PrintRect (PrintRct);
Printer.Orientation := oldPOrient;
end;
end;

The problem is with option in setupdialog window (landscape or portrait).
When portrait is set, chart is printered in landScape (as option indicates before printrect), but when i change it to landscape chart is printered is also as landscape, but teh chart doesn;t fill whole paper, and its height is greater the paper's width ....
What is going on ??
 
Please guys, help me :( Give me any tip, whatever ...
:(
 
The side effects that you see are due to some slight errors in your code.

You have two mistakes:
- First error is where you prepare your PrintRct
You are setting as width of rectangle printers PageHeight
and as height the Pagewidth. Of course it has to be the other way around

- Second one is that you change printer orientation after calculating the Print rectangle area.

Changing the orientation can change the page height and page width of the printer and therefore you would need to recalculate the print rectangle (to get it right).
In your case there is no need to change the orientation.

Have a look at the following code:

Code:
procedure TForm4.Button1Click(Sender: TObject);
var
  PrintRct : tRect;
  OldPOrient : tPrinterOrientation;
begin

  if printersetupdialog1.Execute then
  begin
    OldPOrient := Printer.Orientation;

    //Preparing the draw rectangle (you had a very slight error)
    PrintRct.Top := 0;
    PrintRct.Left := 0;

    //How it was
    //PrintRct.Bottom := Printer.PageWidth-1;
    //PrintRct.Right := Printer.PageHeight-1;

    //Corrected ...
    PrintRct.Bottom := Printer.PageHeight-1;
    PrintRct.Right :=  Printer.PageWidth-1;

    //NOTE:
    //Botttom of rectangle must be set to height of print page
    //Right of rectangle  must be set to width of print page
    //you had them the wrong way arond


    with Chart do begin

      //This line does not belong here
      //Printer.Orientation := poLandScape;

      //Note:
      //Changing printer orientation will change the PageHeight and width
      //therefore you will need to recalculate your PrintRec if you really
      //really had to change the orientation again.

      PrintRect (PrintRct);
      Printer.Orientation := oldPOrient;
    end;

  end;
end;

I hope it helps...


"It is in our collective behaviour that we are most mysterious" Lewis Thomas
 
Yes now it works, Thank You very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top