473,320 Members | 2,109 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,320 software developers and data experts.

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 1173
Hi Neil,

You can determine the size of a String using a given font and Graphics
control using Graphics.MeasureString or Graphics.MeasureCharacterRanges.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
"Neil Kiser" <neil@SPAM_GUARD_REMOVE_TESTkiservilletest.com> wrote in
message news:dn********************************@4ax.com...
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.MeasureString 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_GUARD_REMOVE_TESTkiservilletest.com> wrote in
message news:dn********************************@4ax.com...
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
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...
18
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....
7
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.