PRODUCTS

FEATURED PRODUCT

Create modern-looking & feature-rich applications with over 280 components including award-winning grids, scheduling components, Office 2007/2003 ribbon & toolbars, calendars, application update and much more...

License only 175 EUR See More

SEARCH

LOGIN

Customer login to access products, support information & special benefits.

NEWS ALERTS

Add your e-mail address here to receive the monthly TMS Software alerts.

 

LINKS

EXAMPLE 25

TAdvStringGrid

example 25 : Printing multiple grids on a page

TAdvStringGrid

In some cases, it is flexible to be able to print the contents of multiple grids on a single page. Before v1.90, the grid Print routines encapsulated the complete handling of the print sequence, making it hard to adapt it for printing multiple items on a page. With 2 new methods PrintDraw and PrintDrawRect this is now much easier. The sample project here shows how 4 grids can be printed each on 1/4 of the page. This is the definition of the PrintDraw and PrintDrawRect methods:

PrintDraw(canvas:TCanvas;drawrect:TRect); Print the grid contents in the rectangle drawrect on the canvas.

PrintDrawRect(canvas:TCanvas;drawrect:TRect;gr:TGridRect); Print contents of the cells within the grid rectangle gr, in the rectangle drawrect on the canvas.

The PrintDraw method has been used in the procedure below to print the contents of the 4 grids on a single page. Therefore, the cliprectangle of the printer canvas is obtained and divided in 4 parts and each grid is printed in one quarter of the page. The drawrect indicates the space the grid can use for its printing but not the position ! The position of the grid on the page itself is set with the LeftSize and HeaderSize properties in the PrintSettings. Note that this position is expressed in mm_lometrics units, thus 1/10mm. Therefore, the position is converted from device units to logical units after setting the mapmode to mm_lometrics with the Windows DpToLp method. Further, by setting the PrintSettings.FitToPage to fpShrink, we make sure that the grid is shrinked to the rectangle it is allowed to print in.

procedure TForm1.Button1Click(Sender: TObject);
var
  r:TRect;
  quarterpage:TRect;
begin
  printersetupdialog1.Execute;
  with Printer do
  begin
    BeginDoc;
    r := Canvas.ClipRect;
    quarterpage:=rect(0,0,(r.right-r.left) shr 1,(r.bottom-r.top) shr 1);

    setmapmode(canvas.handle,mm_lometric);
    dptolp(canvas.handle,r,2);

    advstringgrid1.PrintSettings.FitToPage:=fpShrink;
    advstringgrid1.PrintDraw(canvas,quarterpage);

    advstringgrid2.PrintSettings.HeaderSize:=(-r.bottom) shr 1;
    advstringgrid2.PrintSettings.FitToPage:=fpShrink;
    advstringgrid2.PrintDraw(canvas,quarterpage);

    advstringgrid3.PrintSettings.LeftSize:=r.right shr 1;
    advstringgrid3.PrintSettings.FitToPage:=fpShrink;
    advstringgrid3.PrintDraw(canvas,quarterpage);

    advstringgrid4.PrintSettings.LeftSize:=r.right shr 1;
    advstringgrid4.PrintSettings.HeaderSize:=(-r.bottom) shr 1;
    advstringgrid4.PrintSettings.FitToPage:=fpShrink;
    advstringgrid4.PrintDraw(canvas,quarterpage);

    EndDoc;
  end;
end;


Delphi project & source files for downloading included in the main demos distribution for Delphi.

The project and source files have been written with Delphi 6,7. To use these files in other versions of Delphi, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the Delphi 6 form file, but not available in lower versions of Delphi.  

C++Builder project & source files for downloading

The project and source files have been written with C++Builder 5. To use these files in other versions of C++Builder, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the C++Builder form file, but not available in lower versions of C++Builder.

Copyright © 1995 - 2008 TMS Software