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:
Thank you!!
Post a Comment
<< Home