Solved

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

Posted on 2004-10-11
5
526 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
The Using statement in C# 5 37
Windows Management Instrument 6 59
Deserialize JSON array VB.Net problem 3 38
asp.net mvc5 3 38
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now