Solved

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

Posted on 2004-10-11
5
540 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
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 250 total points
ID: 12282894
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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