tags:

views:

24

answers:

2

How to get Width and Height of a specified number of characters ,font Size , font type and font style.

ex : font size = 14
font type = "Times New Roman"
font style = "Regular"
No of Characters = 50

What is the width and height ?

+1  A: 

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

For C#, use MeasureString

ראובן
i am using MFC , please give me sample code or any example.
shubha
+2  A: 

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.

dthorpe
i am using mfc dialog based application,so i have no idea how to calculate width and height , please give me an example.
shubha
In MFC, DrawText is a member of the CDC class. See MSDN for details: http://msdn.microsoft.com/en-us/library/a6x7y2a4.aspx
dthorpe