Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alignment of text in a stringgrid

Status
Not open for further replies.

svanels

MIS
Aug 18, 1999
1,393
SR
Friends, is there a way to align the text in a topdown matter in a cell? If yes how do I achieve that?

Steven
 

Not sure exactly what you mean, but you can process the OnDrawCell event to accomplish whatever kind of formatting you need.

The essential bits are passed in to the event handler in the parameter list:
Code:
  if NeedToFormatThisCell( ACol, ARow ) then
    with TStringGrid(Sender) do
      FormatMyWay( Canvas, Rect, Cells[ACol,ARow] );
and you can create your own functions to support that construct.
Code:
function NeedToFormatThisCell( ACol, ARow: integer): boolean;
begin
  // If this cell needs formatting, return True
  // otherwise return False
end;
and
Code:
procedure FormatMyWay( ACanvas:TCanvas; ARect:TRect; AText:string );
begin
  // Position the text within the rect on the canvas.
end;
For example, I have a routine that checks for a #13#10 in the text. If #13#10 is found, then the text is displayed on two lines inside a TRect. If not then the text is displayed centered vertically inside a TRect.

The trick is to define your own TRect in terms of left,right,top, and bottom (derived from the left,right,top, and bottom of the original TRect) and then use the .TextRect method of the TCanvas to position the text. The .TextWidth property of the TCanvas is also useful for horizontal alignment calculations.


 
I was thinking of rotating the text 90 degrees in the String Grid, for a cause and effect table.
But thanks anyway.

Steven
 
Thanks for the tips, but I found a workaround for my problems.
Just used a StringGrid, some splitters and a CheckListBox to represent the top row of the string. Saved space since the stringgrid can be at 20 x 45 cells

Steven
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top