Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to align string in TStringGrid cell

897 views
Skip to first unread message

Alex Liu

unread,
Aug 5, 2002, 6:50:09 AM8/5/02
to
Dears,

I need to align a Stirng in TStringGrid cell left , right or center.
Anyone can give me suggestion??

I need your help !! Thank you ..

Alex Liu


Steve

unread,
Aug 5, 2002, 8:24:16 AM8/5/02
to
> I need to align a Stirng in TStringGrid cell left , right or center.
> Anyone can give me suggestion??

The following code writes text horizontally centered in the cells. Set
DefaultDrawing to false. It's not complete and I don't know if that's the
quick way, but it could be a hint.

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (State.Contains(gdFixed))
StringGrid1->Canvas->Brush->Color = StringGrid1->FixedColor;
else
StringGrid1->Canvas->Brush->Color = StringGrid1->Color;
StringGrid1->Canvas->FillRect(Rect);
String StringText = StringGrid1->Cells[ACol][ARow];
StringGrid1->Canvas->TextRect(Rect, (Rect.Width() -
StringGrid1->Canvas->TextWidth(StringText)) / 2 + Rect.Left, Rect.Top + 1,
StringText);
if (State.Contains(gdFocused)) StringGrid1->Canvas->DrawFocusRect(Rect);
}

Hope this helps.

Bye,

Steve.


Jackie

unread,
Aug 5, 2002, 8:34:35 AM8/5/02
to
Go to this site
http://www.bridgespublishing.com/articles/articleindex.htm

take a look at
Sepetember 2000 "Working with string grids"
April 2002 "Even more string grids part I"
June 2002 "Even more string grids part II"

it may help , the last tow are optional but is helpful when building a
TStringGrid

A friend call Fishface told me that


"Alex Liu" <alex...@mail.capital.com.tw> 撰寫於郵件
news:3d4e5839$1_1@dnews...

koen smeuninx

unread,
Aug 5, 2002, 8:39:39 AM8/5/02
to
Centers horizontally and vertically.

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{

StringGrid1->Canvas->Brush->Color = clWhite;
StringGrid1->Canvas->FillRect(Rect);
StringGrid1->Canvas->Font->Color=clBlue;
StringGrid1->Canvas->Font->Style=TFontStyles()<< fsBold;
AnsiString StringToAlign=StringGrid1->Cells[ACol][ARow];
int
StringStartH=(Rect.Left+Rect.Right)/2-StringGrid1->Canvas->TextWidth(StringT
oAlign)/2;
int
StringStartV=(Rect.Top+Rect.Bottom)/2-StringGrid1->Canvas->TextHeight(String
ToAlign)/2;
StringGrid1->Canvas->TextOut(StringStartH,StringStartV,StringToAlign);
}
}
"Alex Liu" <alex...@mail.capital.com.tw> wrote in message
news:3d4e5839$1_1@dnews...

Jonathan Arnold

unread,
Aug 5, 2002, 10:09:50 AM8/5/02
to
> I need to align a Stirng in TStringGrid cell left , right or center.
> Anyone can give me suggestion??

You can draw it yourself, like in the methods listed here or
outlined by Damon Chandler at http://bcbcaq.freeservers.com .

Or, even better, you can get a new component that handles it better.
There's a million of them out there. Here's a sampler of some I've found:

Orpheus by TurboPower : huge toolkit, pretty expensive, does everything
http://www.turbopower.com

ExpressGrid by Developer Express :
http://www.devexpress.com/products/vcl/product.asp?prodid=10

Colosseum Builders TColossalGrid : For some reason they've stopped "supporting Borland
products", but:
http://www.colosseumbuilders.com/inprise.htm

ObjectSights's TopGrid : http://www.topsupport.com/

TMS software's TAdvStringGrid : I've used this one in the past and it's pretty good.
http://www.tmssoftware.com/

IMCA Systems TFlyGrid: http://www.imcasys.com/

Woll2Woll's Infopower: http://www.woll2woll.com

ProfGrid : http://www.geocities.com/profgrid

CoolGrid (part of CoolControls) : http://www.cooldev.com

And, of course, check out Torry's for more:

http://www.torry.webnorth.com/index.htm


--
Jonathan Arnold C/C++/CBuilder Keen Advice:
http://www.keen.com/categories/categorylist_expand.asp?sid=5156620
Comprehensive C++Builder link site:
http://www.buddydog.org/C++Builder/c++builder.html

0 new messages