shubha
shubha

Reputation: 1

Width and height of font

How to get the width and height of a specified number of characters, font Size, font type and font style?

Examples:

font size = 14 <br>
font type = "Times New Roman" <br>
font style = "Regular"<br>
No of Characters = 50<br>

What is the width and height?

Upvotes: 0

Views: 2764

Answers (2)

user122299
user122299

Reputation:

In C++, look at the "GetTextExtent" functions. Example:

CDC * dc = GetDC();
dc->SelectObject(GetFont());//select the font you want to measure the text in
CSize size = dc->GetTextExtent(chars);//get the dimensions
size.cx;//width
size.cy;//height

For C#, use MeasureString

Upvotes: 1

dthorpe
dthorpe

Reputation: 36082

For Windows GDI font/display, use DrawText with the DT_CALCRECT flag in the uFormat parameter. It will calculate and return the bounding box for the string you provide using the font currently selected in the HDC.

Upvotes: 1

Related Questions