473,386 Members | 1,621 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,386 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 6355
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.