473,795 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text Window Sizing

I am trying to locate either a sample routine for or to at least
acquire the knowledge of how to determine how large of a window to
create to hold a text string. From my search so far, it would seem
that this is a common request, but I have yet to come across an
example solution.

I have a situation in which I need to size a window accurately, or
either I have to guess what the largest the window could ever be and
set it to a flat number. Really don't want to do this, therefore I'm
in search of a way to determine, given a string, a font, and a window
width, how high the window would need to be to hold the string.

Thank you for any pointers,
-Neil K.
Nov 16 '05 #1
3 1189
Hi Neil,

You can determine the size of a String using a given font and Graphics
control using Graphics.Measur eString or Graphics.Measur eCharacterRange s.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
"Neil Kiser" <neil@SPAM_GUAR D_REMOVE_TESTki servilletest.co m> wrote in
message news:dn******** *************** *********@4ax.c om...
I am trying to locate either a sample routine for or to at least
acquire the knowledge of how to determine how large of a window to
create to hold a text string. From my search so far, it would seem
that this is a common request, but I have yet to come across an
example solution.

I have a situation in which I need to size a window accurately, or
either I have to guess what the largest the window could ever be and
set it to a flat number. Really don't want to do this, therefore I'm
in search of a way to determine, given a string, a font, and a window
width, how high the window would need to be to hold the string.


I don't know if there's a ".NET way" to do this, but you could probably use
the DrawText API function with the DT_CALCRECT option.

Chris Jobson
Nov 16 '05 #3
Hi Neil,

Graphics.Measur eString is the what you need.
You can provide enough info to that method (e.g text wrap, alignment, etc)
to get the size of your window.
The code should be pretty straightforward .

--
Stoitcho Goutsev (100) [C# MVP]

"Neil Kiser" <neil@SPAM_GUAR D_REMOVE_TESTki servilletest.co m> wrote in
message news:dn******** *************** *********@4ax.c om...
I am trying to locate either a sample routine for or to at least
acquire the knowledge of how to determine how large of a window to
create to hold a text string. From my search so far, it would seem
that this is a common request, but I have yet to come across an
example solution.

I have a situation in which I need to size a window accurately, or
either I have to guess what the largest the window could ever be and
set it to a flat number. Really don't want to do this, therefore I'm
in search of a way to determine, given a string, a font, and a window
width, how high the window would need to be to hold the string.

Thank you for any pointers,
-Neil K.

Nov 16 '05 #4

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

Similar topics

9
7708
by: Peter | last post by:
Hi at all, how can I do to make a css file to change automatically the text size of the text that is into a table relatively the screen size? I.E. if the screen is 800 x I want the text size=10pt but if it is 1024 I want the text size =12 pt. Thank in advance Peter
18
2518
by: Roger Withnell | last post by:
I open a new window from the current window to display maps. Several maps of different sizes can be displayed. The function is given the size of the map and adjusts the window size accordingly. If a new window is already open, the new map sizes are ignored and the new map is is either too small for the existing "new" window or too big, which is a more serious problem! I've tried to fix this by closing the new window if it is already...
7
3345
by: Yeah | last post by:
Ever since I upgraded my Windows display to 120 DPI (kind of a necessary change), fonts have been clearer and graphics have been crisper. However, the 25% automatic increase in the text size on my web site has thrown it all askew. Combining my monitor's native resolution of 1280x1024 and the XP setting of 120 DPI, everything else is great, but now standard Serif on my web site looks like I'm reading a Dr. Seuss book. Obviously,...
1
4225
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.