Solved

Alignment in a StringGrid

Posted on 2001-07-25
3
3,051 Views
Last Modified: 2012-08-13

Hi,
How can I align text in a stringgrid ?  I want some text on left, center ant right align.
Like this :

|  name  |    tel    |  Amount  |
|John    |555-1234   |     5.00 |
|Dona    |555-9999   |   125.00 |

Thanks
0
Comment
Question by:frdep
3 Comments
 
LVL 3

Accepted Solution

by:
VSF earned 100 total points
ID: 6319478
Hope this helps

VSF
www.victory.hpg.com.br
www.enge.cjb.net


ALLING CELLS IN A STRINGGRID
I need to allign cells in a stringgrid, first cell to the left ,second to the right and so on ...
Answer:
procedure WriteText(ACanvas: TCanvas; const ARect: TRect; DX, DY: Integer;
                    const Text: string; Format: Word);
var
  S: array[0..255] of Char;
  B, R: TRect;

begin
  with ACanvas, ARect do
  begin
     case Format of
        DT_LEFT   : ExtTextOut(Handle, Left + DX, Top + DY, ETO_OPAQUE or ETO_CLIPPED,
                               @ARect, StrPCopy(S, Text), Length(Text), nil);

        DT_RIGHT  : ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top + DY,
                               ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text),
                               Length(Text), nil);

        DT_CENTER : ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2,
                               Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect,
                               StrPCopy(S, Text), Length(Text), nil);
     end;
  end;
end;


procedure TBEFStringGrid.DrawCell(Col, Row: Longint; Rect: TRect; State: TGridDrawState);
var

   procedure Display(const S: string; Alignment: TAlignment);
   const
      Formats: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
   begin
      WriteText(Canvas, Rect, 2, 2, S, Formats[Alignment]);
   end;

begin
   { test the Col and Row arguments here and format the cells as you want }

   case Row of
   0     : { Center column headings }
           if (Col < ColCount) then
              Display(Cells[Col,Row], taCenter)
   else
      { Right justify all other entries }
      Display(Cells[Col,Row], taRight);
   end;

end;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8733765
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept VSF's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question