Solved

Alignment in a StringGrid

Posted on 2001-07-25
3
3,045 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now