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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:02:16+00:00 2026-06-18T19:02:16+00:00

How can one make a CStatic with text auto-wrap (multiline) which vertically centeres the

  • 0

How can one make a CStatic with text auto-wrap (multiline) which vertically centeres the result in the control’s rectangle?

The problem I’m trying to solve is this: I have a CStatic control next to a CComboBox which updates information text depending on the choice. This text can be either short or long, requiring the CStatic to sometimes use multi-lines, and sometimes not. I want the info-text be vertically center-aligned with the CComboBox.

Now here is the problem:

  • If I make the CStatic only 1 textline high, it looks good for 1-line texts, but multi-lines do not fit and are not displayed.

  • If I make the CStatic higher to fit 2 lines, it looks good for long texts (with 2 lines), but 1-line-texts are shifted upwards, as the CStatic aligns the text on the top. A CStatic with the behavior mentioned in the question would solve this…

If I can’t easily get a vertically centered CStatic multi-line control, the alternative would be to resize the control rect depending on the amount of text in it. But in this case I have a different problem:

How can I programatically find out how many lines a text will need in a CStatic of specific width?

  • 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-06-18T19:02:18+00:00Added an answer on June 18, 2026 at 7:02 pm

    Unfortunately you can’t vcenter multi-line text in a CStatic.

    Your next question has a solution but it’s a bit of a pain to use. What you do is you use CDC::DrawTextEx with the DT_CALCRECT flag to get the size (in pixels) of the text you want to format. By dividing that by the height of a line of text (given in the font info you can get from the DC, plus some spacing which I’m not sure of how much that is – presumably it’s a fixed amount, I don’t think you can specify line spacing with DrawText), you will get (an approximation of) the number of lines you will get. You can then resize the control rect.

    Come to think of it, you are probably better off not converting to lines and just resize your control to the extent you get from DrawTextEx 🙂

    Things like this usually require some experimentation to get exactly right, and sometimes behave differently between OS versions. Proceed with caution.

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

Sidebar

Related Questions

Is there a way that one can make a control, such as a textbox,
Problem I have an app where one can make pledges against a gift. Once
How can one make recursive Glob() in a VariantDir() environment in Python? The answer
How can we make one database restore date to date, like sunday to wednesday
Can any one tell me how can I make divs visible in ASP.NET. I
http://jsfiddle.net/DaJWC/ i can't figure out how to make one of the links reverse so
I am new to android.So i can any one sho me how to make
In Java, how can you make an ArrayList read-only (so that no one can
All I can make out is that one of them is the BC for
How can I make a vertical UISlider? I saw it in one of the

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.