Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Print a TStringGrid Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
24-Jan-03
Category
Reporting /Printing
Language
Delphi 2.x
Views
75
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

How to Print a TStringGrid

Answer:

Here's the code.  Just whack this onto a form's code and away you go.....
1   
2   procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
3   var
4     X1, X2: Integer;
5     Y1, Y2: Integer;
6     TmpI: Integer;
7     F: Integer;
8     TR: TRect;
9   begin
10    Printer.Title := sTitle;
11    Printer.BeginDoc;
12    Printer.Canvas.Pen.Color := 0;
13    Printer.Canvas.Font.Name := 'Times New Roman';
14    Printer.Canvas.Font.Size := 12;
15    Printer.Ccnvas.Font.Style := [fsBold, fsUnderline];
16    Printer.Canvas.TextOut(0, 100, Printer.Title);
17    for F := 1 to sGrid.ColCount - 1 do
18    begin
19      X1 := 0;
20      for TmpI := 1 to (F - 1) do
21        X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
22      Y1 := 300;
23      X2 := 0;
24      for TmpI := 1 to F do
25        X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
26      Y2 := 450;
27      TR := Rect(X1, Y1, X2 - 30, Y2);
28      Printer.Canvas.Font.Style := [fsBold];
29      Printer.Canvas.Font.Size := 7;
30      Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
31      Printer.Canvas.Font.Style := [];
32      for TmpI := 1 to sGrid.RowCount - 1 do
33      begin
34        Y1 := 150 * TmpI + 300;
35        Y2 := 150 * (TmpI + 1) + 300;
36        TR := Rect(X1, Y1, X2 - 30, Y2);
37        Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
38      end;
39    end;
40    Printer.EndDoc;
41  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC