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 920459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:43:05+00:00 2026-05-15T18:43:05+00:00

Does anyone know how to get the width and height of text in a

  • 0

Does anyone know how to get the width and height of text in a TRichEdit control, in the same way that you would use TextWidth and TextHeight on a TCanvas?

The reason I need to know this doing this is I have a RichEdit on a non-visible form that I copy the contents of to a canvas using Richedit.Perform(EM_FORMATRANGE, …). The problem is that the EM_FORMATRANGE requires a parameter of type TFormatRange in which the target rect is specified, but I don’t know what the rect should be because I don’t know in advance the size of the contents in the RichEdit. Hope that makes sense.

  • 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-15T18:43:05+00:00Added an answer on May 15, 2026 at 6:43 pm

    Again use EM_FORMATRANGE for measuring, see EM_FORMATRANGE Message on MSDN:

    wParam Specifies whether to render the
    text. If this parameter is a nonzero
    value, the text is rendered.
    Otherwise, the text is just measured.

    Generally you would already have a destination area, which has a width and height, where you’d do the drawing, like printing on a paper or producing a preview on a predefined surface. A most simple example for a predefined width to get the required height could be;

    var
      Range: TFormatRange;
      Rect: TRect;
      LogX, LogY, SaveMapMode: Integer;
    begin
      Range.hdc := ACanvas.Handle;
      Range.hdcTarget := ACanvas.Handle;
    
      LogX := GetDeviceCaps(Range.hdc, LOGPIXELSX);
      LogY := GetDeviceCaps(Range.hdc, LOGPIXELSY);
    
      Range.rc.Left := 0;
      Range.rc.Right := RichEdit1.ClientWidth * 1440 div LogX; // Any predefined width
      Range.rc.Top := 0;
      Range.rc.Bottom := Screen.Height * 1440 div LogY; // Some big number
      Range.rcPage := Range.rc;
      Range.chrg.cpMin := 0;
      Range.chrg.cpMax := -1;
      RichEdit1.Perform(EM_FORMATRANGE, 0, Longint(@Range));
    
      ShowMessage(IntToStr(Range.rc.Bottom * LogY div 1440)); // Get the height
      RichEdit1.Perform(EM_FORMATRANGE, 0, 0); // free cache
    

    For a more complete example see this article, or in general any RichEdit previewing/printing code…

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

Sidebar

Related Questions

Does anyone know how I can get a format string to use bankers rounding
Does anyone know if there is way to get the sender and the eventarguments
Does anyone know if there's a way to get Eclipse to do a Save
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does anyone know how to get the MS Office 2007 .NET C# Interop libraries
Does anyone know how to get the below to report a javascript error? (any
Using C#, does anyone know how to get the MarshalAsAttribute's Sizeconst value in runtime
Does anyone know how I can get rid of the following assembler warning? Code
Does anyone know if it's possible to get a Win32 application to run under
Does anyone know if there is an API to get the current monitor state

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.