Solved

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

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

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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