Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7409995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:54+00:00 2026-05-29T06:09:54+00:00

I have a standard TStringGrid on a form. I have one Fixed Row in

  • 0

I have a standard TStringGrid on a form.
I have one Fixed Row in the grid that contains a number of columns, which are all TGridColumns objects. I have set the column titles using the object inspector and the default orientation is horizontal. Is there any way you can make the orientation vertical (like you can in cells in Excel)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:09:55+00:00Added an answer on May 29, 2026 at 6:09 am

    Here’s how to render the first row’s text vertically in Lazarus:

    unit Unit1; 
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids,
      StdCtrls;
    
    type
      TStringGrid = class(Grids.TStringGrid)
      protected
        procedure DrawCellText(ACol, ARow: Integer; ARect: TRect;
          AState: TGridDrawState; AText: String); override;
      end;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        StringGrid1: TStringGrid;
        procedure Button1Click(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end; 
    
    var
      Form1: TForm1; 
    
    implementation
    
    {$R *.lfm}
    
    procedure TStringGrid.DrawCellText(ACol, ARow: Integer; ARect: TRect;
      AState: TGridDrawState; AText: String);
    var
      TextPosition: TPoint;
    begin
      if ARow = 0 then
      begin
        Canvas.Font.Orientation := 900;
        TextPosition.X := ARect.Left +
          ((ARect.Right - ARect.Left - Canvas.TextHeight(AText)) div 2);
        TextPosition.Y := ARect.Bottom -
          ((ARect.Bottom - ARect.Top - Canvas.TextWidth(AText)) div 2);
        Canvas.TextOut(TextPosition.X, TextPosition.Y, AText);
      end
      else
        inherited DrawCellText(ACol, ARow, ARect, AState, AText);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
      GridColumn: TGridColumn;
    begin
      for I := 0 to 4 do
      begin
        GridColumn := StringGrid1.Columns.Add;
        GridColumn.Width := 24;
        GridColumn.Title.Font.Orientation := 900;
        GridColumn.Title.Layout := tlBottom;
        GridColumn.Title.Caption := 'Column no. ' + IntToStr(I);
      end;
      StringGrid1.RowHeights[0] := 80;
    end;
    
    end.
    

    Here’s how to render the first row’s text of the TStringGrid vertically in Delphi:

    I would prefer to use the overriden DrawCell procedure because it seems to me as the easiest way to go because if you want to render the text simply in the OnDrawCell event then you should consider:

    • if you’ll have the DefaultDrawing set to True then the text will already be rendered when the OnDrawCell event is fired, so here I would recommend e.g. to store the cell captions in a separate variable, not into Cells property so then no text will be rendered and you can draw your own stored captions vertically
    • if you’ll have the DefaultDrawing set to False then you’ll have to draw the whole cell by your own, including the 3D border, what is IMHO not so cool, and I would personally prefer to let the control draw the background for us

    Here is the Delphi code which uses the overriden DrawCell procedure. The text is being centered inside of the cell rectangle; please note that I haven’t used the DrawTextEx for text size measurement because this function doesn’t take the changed font orientation into account.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Grids;
    
    type
      TStringGrid = class(Grids.TStringGrid)
      protected
        procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
          AState: TGridDrawState); override;
      end;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        StringGrid1: TStringGrid;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
      AState: TGridDrawState);
    var
      LogFont: TLogFont;
      TextPosition: TPoint;
      NewFontHandle: HFONT;
      OldFontHandle: HFONT;
    begin
      if ARow = 0 then
      begin
        GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont);
        LogFont.lfEscapement := 900;
        LogFont.lfOrientation := LogFont.lfEscapement;
        NewFontHandle := CreateFontIndirect(LogFont);
        OldFontHandle := SelectObject(Canvas.Handle, NewFontHandle);
        TextPosition.X := ARect.Left +
          ((ARect.Right - ARect.Left - Canvas.TextHeight(Cells[ACol, ARow])) div 2);
        TextPosition.Y := ARect.Bottom -
          ((ARect.Bottom - ARect.Top - Canvas.TextWidth(Cells[ACol, ARow])) div 2);
        Canvas.TextRect(ARect, TextPosition.X, TextPosition.Y, Cells[ACol, ARow]);
        NewFontHandle := SelectObject(Canvas.Handle, OldFontHandle);
        DeleteObject(NewFontHandle);
      end
      else
        inherited DrawCell(ACol, ARow, ARect, AState);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to StringGrid1.ColCount - 1 do
      begin
        StringGrid1.ColWidths[I] := 24;
        StringGrid1.Cells[I, 0] := 'Column no. ' + IntToStr(I);
      end;
      StringGrid1.RowHeights[0] := 80;
    end;
    
    end.
    

    And here’s how it looks like:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have standard .net 2.0 gridview control from which i want to get row
I am running Lazarus 0.9.30. I have a standard TStringGrid on a form and
I have standard basic article content type which, amongst other things, contains an image
I have a web application that have standard form authentication declared, like this: <login-config>
I have the standard setup of one main image and multiple thumbnails which can
I have a standard form with a textbox with tinymce invoked. All is well
I have standard text links which all say Full View. When clicked these links
Many languages have standard repositories where people donate useful libraries that they want others
I have a standard windows server that inherits from the ServiceBase class. On the
I have standard class library infrastructure assembly which i reference in my main application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.