?
Solved

How to get the width of a character in pixels? -- vb.net

Posted on 2004-10-11
5
Medium Priority
?
583 Views
Last Modified: 2012-05-05
** vb.net **
I need to dynamically size my column header based on the text that is retrieved for the column header text.
If the column header is "XXXX" characters long, how do I convert this to its equivalent  pixels
Thanks
0
Comment
Question by:vbothello
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 12278631
try this

Imports System.Drawing.Graphics


 Dim g As Graphics = TextBox1.CreateGraphics()
  Dim size As SizeF = g.MeasureString(string1, TextBox1.Font)

Then size.Width will have the width in pixels of the string as it would be if
drawn in Textbox1


length in bytes
System.Text.Encoding.Default.GetByteCount

0
 

Author Comment

by:vbothello
ID: 12279645
that's nice but I am not using a textbox , its just a column header on a grid , for now I just calculated the length of characters on the column header text , and multiplied it by an arbitrary number to give me the pixels , I know its not the right way to do it but would love to know the right way to calculate the pixels.
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 750 total points
ID: 12282894
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question