Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2005

Tip: Looking for answers? Try searching our database.

Determining length of a string in pixels

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HaySeed - 08 Dec 2005 22:27 GMT
I am drawing text on a screen using graphicsObject.DrawString().

Prior to doing this I need to determine the length in pixels that the string
will be when it is rendered.  I know I've read this before but can not find
it now that I need it.

Also - is there a simple way to center the text within a rectangel?

And - Thanks for your responses I really appreciate it!
Herfried K. Wagner [MVP] - 08 Dec 2005 22:49 GMT
Hi,

"HaySeed" <HaySeed@discussions.microsoft.com> schrieb:
>I am drawing text on a screen using graphicsObject.DrawString().
>
[quoted text clipped - 3 lines]
> find
> it now that I need it.

Check out the 'Graphics' object's 'MeasureString' method.

> Also - is there a simple way to center the text within a rectangel?

There is an overloaded version of 'DrawString' which has parameters
'layoutRectangle' and 'format'.  You can specify the alignment in the
'StringFormat' passed to the 'format' parameter.

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.