[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Any way to determine the width of text when it is drawn?  ASP.NET VB

Posted on 2013-02-03
3
Medium Priority
?
308 Views
Last Modified: 2013-02-03
Here is my line of code which draws text to the screen:

Dim TopLine1 as string = "Hello World"

graphicImage.DrawString(TopLine1, New Font("Helvetica, sans-serif", 18, FontStyle.Regular), SystemBrushes.WindowText, New Point(GetLeftMargin(TopLine1), 20))


I need to create the function GetLeftMargin which will center the text within my area, which is 440 pixels wide.   Since most fonts do not have a "fixed" width for each character, I can't simply take the number of characters and multiply by a fixed pixel width.

My hope is to pre-calculate the width of the string I am drawing, and then use that to calculate my X margin.  If I knew how wide my text image was, then I could quickly calculate the correct margin for it.   How can I pre-calculate how wide my text image is going to be?
0
Comment
Question by:arthurh88
[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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
MajorBigDeal earned 2000 total points
ID: 38849138
0
 

Author Comment

by:arthurh88
ID: 38849149
thanks a bunch!  this worked too, i discovered right as you answered:

 Dim Tlength As Integer = graphicImage.MeasureString(String.Format("{0:C2}", TopLine1), New Font("Helvetica, sans-serif", 18, FontStyle.Regular)).Width
0
 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 38849514
Cool, thanks for sharing your solution.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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