473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fontmetrics


What is the easiest way to get the width of a string based on font metrics?
Nov 17 '05 #1
2 4764

Gene Vital wrote:
What is the easiest way to get the width of a string based on font metrics?


System.Drawing.Graphics has an instance method MeasureString that takes
a Font and a String and returns a SizeF.

Adam

Nov 17 '05 #2
In addition to Adam's answer you can use MeasureCharacterRanges for a more
accurate result in some cases.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Adam" <ad************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Gene Vital wrote:
What is the easiest way to get the width of a string based on font
metrics?


System.Drawing.Graphics has an instance method MeasureString that takes
a Font and a String and returns a SizeF.

Adam

Nov 17 '05 #3

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

Similar topics

4
9298
by: Doug van Vianen | last post by:
Hi, I am working on an Applet which provides some mouse practice for new computer users in our local seniors' computer club. The applet contains several cards, in a card layout, which are...
2
3534
by: fabien | last post by:
Hi, I am writing a POV-RAY editor with Python using either QT or GTK as GUI 'wrapper'. ( I am still trying both ) * * * * PYGTK * * * * I have downloaded PygtkScintilla-1.99.5. There is a...
5
12701
by: Steve | last post by:
I need a way to programatically change the width of a textbox to display all the data knowing the font, font size and number of characters. Does any oone know of a reference somewhere ot a way to...
3
2276
by: onetitfemme | last post by:
when you get and objects offsets, width and height properties they are given as pixels, "px". .. Does JS has a internal function and/or cross browser hack to: .. 1._ check the font size of a...
0
3042
by: raji20 | last post by:
Hello Guys, Im using pdflib for generating pdf, It is working fine, when I used a single page pdf as the template, but when I use a pdf with two pages I dont know how to write in first page and...
10
2833
by: dishal | last post by:
Hi, im having a major problem with printing text on a JFrame. This is a simple whiteboard I'm doing but i just cannot seem to print the text properly. It prints all the alphabets on the same point...
1
2127
by: dishal | last post by:
Hi, Im having a problem with typing on the JPanel. The thing is, that it works perfectly fine when this line " content.add(jp, BorderLayout.NORTH); " is taken out (its the buttons panel) but when its...
1
2073
by: kiberg | last post by:
Hi Graphics g; g.drawString("Hello World!", 10, 10); I don't know it what kind of wide the text.How to calculate it? ThAnKs!
14
2933
jhardman
by: jhardman | last post by:
I am having a hard time opening a text file from an applet. I remembered after an attempt or two that there were obvious security issues here, so I switched the code to pull a text file off the...
0
7108
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,...
0
7142
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,...
0
7181
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...
1
6847
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...
0
7352
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...
0
4565
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...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.