Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 





How to determine wether a string fits in a textbox (Thursday, August 19, 2004)


Find out wether a string fits in a textbox

Often the problem occurs that a string doesn't completely fit in a textbox. Since not every character has the same dimensions a method has to be found to measure the width in pixels of a text string. The following example shows how.

You can use the 'Graphics.MeasureString' method:

'VB
Dim myGraphic As Graphics = myTextBox.CreateGraphics()
Dim myStringSize As SizeF = myGraphic.MeasureString(string1, myTextBox.Font)


The myStringSize.Width method returns the width in Pixels of the String that would be drawn in the TextBox 'MyTextBox'


Posted by Xander Zelders



1 Comments:

Anonymous Anonymous said...

Thank you!!

8:23 PM  

Post a Comment

<< Home

 
Previous Posts
    - How to play sounds using the .NET framework
    - Howto convert strings from lower case to upper cas...
    - How to read images from an Access database (OLE ob...
    - How to Print from a rich text box
    - Pure ASP.NET
    - Visual Basic .NET Code Security Handbook
    - Obfuscating .NET: Protecting Your Code from Prying...
    - Database Programming with Visual Basic .NET and AD...
    - Moving to VB .NET
    - Hijacking .Net Vol 2: Protecting Your Code [DOWNLO...



Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland