• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

Center Text In StrinGrid Cell

How can I center text in a stringgrid
cell?
0
brettawv
Asked:
brettawv
1 Solution
 
rene100Commented:
hi...

you can use this function:

function CenterTextInRect(Canvas: TCanvas; Text: string; DestRect: TRect; DrawIt: Bool): TRect;
var
Size: TSize;
XPos,YPos,XRange,YRange: Integer;
begin
Size:=Canvas.TextExtent(Text);
XRange:=DestRect.Right-DestRect.Left;
YRange:=DestRect.Bottom-DestRect.Top;
XPos:=DestRect.Left+Round(XRange/2)-Round(Size.cx/2);
YPos:=DestRect.Top+Round(YRange/2)-Round(Size.cy/2);
Result.Left:=XPos;
Result.Top:=YPos;
If DrawIt=True then
   Canvas.TextOut(XPos,YPos,Text);
end;

regards
rene


0
 
intheCommented:
hi,
see the "Drawgrid" example here for code:

http://home.ican.net/~wniddery/freedelphistuff.html

or if you want component instead thee is one at torrys called stringAlignGrid :

http://www.torry.ru/vcl/grids/aligrid.zip


Regards Barry

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now