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 create a multiple line heading in 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
05-Nov-02
Category
VCL-General
Language
Delphi All Versions
Views
75
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to create a multiple line heading in a TStringGrid

Answer:

Here is an example for a TStringGrid that has a multiple line heading with centered 
and bold text:
1   
2   procedure TForm1.grid1DrawCell(Sender: TObject; Col, Row: Longint;
3     Rect: TRect; State: TGridDrawState);
4   var
5     l_oldalign: word;
6     l_YPos, l_XPos, i: integer;
7     s, s1: string;
8     l_col, l_row: longint;
9   begin
10    l_col := col;
11    l_row := row;
12    with sender as TStringGrid do
13    begin
14      if (l_row = 0) then
15        canvas.font.style := canvas.font.style + [fsbold];
16      if l_row = 0 then
17      begin
18        l_oldalign := settextalign(canvas.handle, ta_center);
19        l_XPos := rect.left + (rect.right - rect.left) div 2;
20        s := cells[l_col, l_row];
21        while s <> '' do
22        begin
23          if pos(#13, s) <> 0 then
24          begin
25            if pos(#13, s) = 1 then
26              s1 := ''
27            else
28            begin
29              s1 := trim(copy(s, 1, pred(pos(#13, s))));
30              delete(s, 1, pred(pos(#13, s)));
31            end;
32            delete(s, 1, 2);
33          end
34          else
35          begin
36            s1 := trim(s);
37            s := '';
38          end;
39          l_YPos := rect.top + 2;
40          canvas.textrect(rect, l_Xpos, l_YPos, s1);
41          inc(rect.top, rowheights[l_row] div 3);
42        end;
43        settextalign(canvas.handle, l_oldalign);
44      end
45      else
46      begin
47        canvas.textrect(rect, rect.left + 2, rect.top + 2, cells[l_col, l_row]);
48      end;
49      canvas.font.style := canvas.font.style - [fsbold];
50    end;
51  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