I have recently been working on a project that requires the use of vertical text within the first row of a Stringgrid.
When I change the drawing style of the Stringgrid to gdsThemed, the vertical text displays , however the text is also displayed horisontaly accross the cell.

Here is the code i got to display the text vertically,

procedure TForm1.StringGridRotateTextOut2(Grid:TStringGrid;ARow,ACol:Integer;Rect:TRect;
          Schriftart:String;Size:Integer;Color:TColor;Alignment:TAlignment);
var
    NewFont, OldFont : Integer;
    FontStyle, FontItalic, FontUnderline, FontStrikeout: Integer;
begin
   // if the font is to big, resize it
   // wenn Schrift zu groß dann anpassen
   If (Size > Grid.ColWidths[ACol] DIV 2) Then
       Size := Grid.ColWidths[ACol] DIV 2;
   with Grid.Canvas do
   begin
       // Set font
       // Font setzen
       If (fsBold IN Font.Style) Then
          FontStyle := FW_BOLD
       Else FontStyle := FW_NORMAL;

       If (fsItalic IN Font.Style) Then
          FontItalic := 1
       Else FontItalic := 0;

       If (fsUnderline IN Font.Style) Then
          FontUnderline := 1
       Else FontUnderline := 0;

       If (fsStrikeOut IN Font.Style) Then
          FontStrikeout:=1
       Else FontStrikeout:=0;

       Font.Color := Color;
       NewFont := CreateFont(Size, 0, 900, 0, FontStyle, FontItalic,
                             FontUnderline, FontStrikeout, DEFAULT_CHARSET,
                             OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                             DEFAULT_PITCH, PChar(Schriftart));

       OldFont := SelectObject(Handle, NewFont);
       // fill the rectangle
       // Rechteck füllen
       FillRect(Rect);
       // Write text depending on the alignment
       // Text nach Ausrichtung ausgeben
       If Alignment = taLeftJustify Then
          TextRect(Rect,Rect.Left+2,Rect.Bottom-2,Grid.Cells[ACol,ARow]);
       If Alignment = taCenter Then
          TextRect(Rect,Rect.Left+Grid.ColWidths[ACol] DIV 2 - Size + Size DIV 3,
            Rect.Bottom-2,Grid.Cells[ACol,ARow]);
       If Alignment = taRightJustify Then
          TextRect(Rect,Rect.Right-Size - Size DIV 2 - 2,Rect.Bottom-2,Grid.Cells[ACol,ARow]);

       // Recreate reference to the old font
       // Referenz auf alten Font wiederherstellen
       SelectObject(Handle, OldFont);
       // Recreate reference to the new font
       // Referenz auf neuen Font löschen
       DeleteObject(NewFont);
   end;
end;

And this is how I call it,

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      If ARow = 0 then
        StringGridRotateTextOut2(StringGrid1,ARow, ACol, Rect, 'ARIAL', 18, clBlack,taCenter);
      StringGrid1.Update;
    end;

What can I do to display only the vertical text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.