Board index » delphi » Aligning Text in StringGrid

Aligning Text in StringGrid

How do one go about to align text in a stringgrid,
say for example i've got a floatfield and wish to display it right aligned.

I cant find the property to set.

Thanks in advance

Conrad Smith

 

Re:Aligning Text in StringGrid


Conrad Smith <sof...@icon.co.za> wrote in article
<34195819.1...@icon.co.za>...

Quote
> How do one go about to align text in a stringgrid,
> say for example i've got a floatfield and wish to display it right

aligned.

Conrad,

set DefaultDrawing to False. Then handle the OnDrawCell yourself. The Col
and Row parameters tell you wich cell you are drawing, the Rect parameter
gives the co-ordinates  of the cell in question. You can use the TextOut
method of the Canvas property of the StringGrid to write text in the grid
and the TextWidth method to find out what the width of the text is in
pixels. So to right-align you would do something like:

with MyGrid, Canvas do begin
  W := TextWidth(Cells[ACol, ARow]);
  TextOut(ARect.Right-W-4, ARect.Top+2, Cells[ACol, ARow]);
end;

You can set a font, brush etc. first and/or do some drawing too.

Wim

Re:Aligning Text in StringGrid


Quote
Conrad Smith wrote:

> How do one go about to align text in a stringgrid,
> say for example i've got a floatfield and wish to display it right aligned.

> I cant find the property to set.

Get the Free w. sources StringAlignGrid from SuperPage. The documentation
is poor, but the product is good.
Double click this Grid with mouse, and then again with the right mouse
button, and understandable menu to do alignment etc. gets open.

Markku Nevalainen

Re:Aligning Text in StringGrid


Quote
Markku Nevalainen <mnevalaiNOS...@netlife.fi> wrote:
> Get the Free w. sources StringAlignGrid from SuperPage. The documentation
> is poor, but the product is good.

Thanks for promoting my product - I know I have to work on the documentation,
but it's just that programming is much more fun than documenting...

Instead going to the Delphi Super Page you should go directly to my homepage
as I just put a new release (V1.6) there and haven't yet uploaded it to DSP -
especially if you want to use it with Delphi 3 you should use the new one as
the old version made D3 quite unstable.

Bye,
   Andy

----------------------------------------------------------------------------
Andreas H"orstemeier                       | "Wenn ist das Nunstueck git
email: a...@scp.de                           | und Slotermeyer? Ja! Beiherhund
       a...@farpoint.westend.de            | das Oder die Flipperwaldt
www:   http://www.westend.de/~hoerstemeier | gersput."
fido:  2:2452/108                          |                  (Monty Python)
----------------------------------------------------------------------------  

Other Threads