473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

string width in pixels

How can I mesure string width in pixels?
I found : Graphics.MeasureString Method.
It is in System.Drawing namespace.
I need to use it in static library.
Well, class Graphics does not have any constructors (at least in my MSDN).

So, if I can't use System::Drawing::Graphics::MeasureString in static lib,
and Graphics *g = new System::Drawing::Graphics() does not work.
How can I call MeasureString Method?

Or if someone knows how to mesure lets say CString width in pixels.
Or auto size CStatic to it's content (runtime implementation).

Thanks, Rajko.
Nov 17 '05 #1
2 6354
Rajko wrote:

How can I mesure string width in pixels?
I found : Graphics.MeasureString Method.
It is in System.Drawing namespace.
I need to use it in static library.
Well, class Graphics does not have any constructors (at least in my MSDN).

So, if I can't use System::Drawing::Graphics::MeasureString in static lib,
and Graphics *g = new System::Drawing::Graphics() does not work.
How can I call MeasureString Method?

Or if someone knows how to mesure lets say CString width in pixels.
Or auto size CStatic to it's content (runtime implementation).

Thanks, Rajko.


Use Win32 DrawText w/ the DT_CALCRECT flag.
Nov 17 '05 #2
Thx, Julie.
I used CDC.GetTextExtent(str).
GetTextExtent and DrawText do the same thing.
They don't calculate str correctly.
In case string is "IIIIIIIIIIIII" they do OK, but when string is "mmmmmm"
they calculate "mmmmmm " ????
MSDN says thet they don't care for forn kerning and that may be it but i
wont to create dialog control dinamicaliy and need more accurate function.

Thanks, Rajko.
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Rajko wrote:

How can I mesure string width in pixels?
I found : Graphics.MeasureString Method.
It is in System.Drawing namespace.
I need to use it in static library.
Well, class Graphics does not have any constructors (at least in my MSDN).
So, if I can't use System::Drawing::Graphics::MeasureString in static lib, and Graphics *g = new System::Drawing::Graphics() does not work.
How can I call MeasureString Method?

Or if someone knows how to mesure lets say CString width in pixels.
Or auto size CStatic to it's content (runtime implementation).

Thanks, Rajko.


Use Win32 DrawText w/ the DT_CALCRECT flag.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Simon Wigzell | last post by:
I am adapting a javascript pulldown menu system to my dynamic website generator - the arrays that hold the menu items information are read from a database and will be different for different users...
179
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
157
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript...
4
by: | last post by:
--------------- <style> td.left {width: 20px; background-image: url(left_tab.png)} td.m {background-image: url(middle_tab.png)} td.right {width: 20px; background-image: url(right_tab.png)}...
18
by: day | last post by:
I know I've seen this issue described before, but I can't find it, or the solution now that I need it. I have some css-specified floating divs that contain images or text. The text divs have a...
6
by: Cathie Hagen | last post by:
Hi All, I am trying to work out how to find the string-length in pixels (any units would do at this stage) for my document so I can determine column width. Any ideas? Cathie
2
by: neuneudr | last post by:
Hi everybody, I'm scratching my head with a CSS problem. I want to have the following (the two pics have these size for a good reason, the whole point of the page is basically to show these...
7
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
4
by: p.numminen | last post by:
Is it possible, with CSS, to determine a certain _maximum_ width for a text, paragraph, division, etc.?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.