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

  • SEARCH
  • Home
  • 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 6341793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:06:33+00:00 2026-05-24T20:06:33+00:00

How to automatically resize TStringGrid row (DefaultRowHeight) to match the height of the font

  • 0

How to automatically resize TStringGrid row (DefaultRowHeight) to match the height of the font used?
I do something like

Grid.DefaultRowHeight:= Grid.Canvas.TextHeight(‘X’) + 4;

but it is not working. For small fonts, the height of the rows is way too big.


Update:

It seems to be actually a problem with program’s logic. If I change the font multiple times, the current height of the row matches the size of the font from previous font change event (it is one step behind).

I use this code to intercept font’s size change:

procedure TStrGrid.CMFontChanged(var Message: TMessage);
begin
  inherited; // let TControl react first
  DefaultRowHeight:= Canvas.TextHeight('ApApM')+ 4;
end;

It acts as if the procedure will be:

begin
  DefaultRowHeight:= Canvas.TextHeight('ApApM')+ 4;
  inherited; 
end;

(like first it changes the height, then it actually sets the correct font size – therefore the height is one step behind)

  • 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-24T20:06:35+00:00Added an answer on May 24, 2026 at 8:06 pm

    It has nothing to do with this order: both the inherited CMFontChanged message handler and the DefaultRowHeight property setter call invalidate. It is due to the current font setting which is not yet updated:

    procedure TStrGrid.CMFontchanged(var Message: TMessage);
    begin
      Canvas.Font := Font;
      DefaultRowHeight := Canvas.TextHeight('Ap') + GridLineWidth + 3;
    end;
    

    Explanation:

    Invalidate only flags windows to repaint the window (the grid) somewhere in future. That happens certainly after obtaining the text height. As alternative you can call Repaint prior to the request for the new text height, but that would result in a double repaint, hence setting Canvas.Font.

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

Sidebar

Related Questions

I would like my Canvas to automatically resize to the size of its items,
Silverlight virgin here. How do I make the usercontrol surrounding my grid automatically resize
I would like to automatically resize div according the background-image size. Is that possible
So I automatically resize my iframe based on content height as follows: <a href=#
I have a simple question. Can a grid automatically resize the objects in it
How should I resize an image with Python script so that it would automatically
How can I make a CListCtrl to resize the width of its columns automatically?
Gmail automatically greys text that looks like a signature. Anyone have any guesses how
I would like to automatically convert between tabs and spaces for indentation when I
I'd like to automatically generate database scripts on a regular basis. Is this possible.

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.