2

Having VB textbox control with fixed width. How to measure or set font size of the control for given string length ? The string/text should fit into the textbox completly.

1 Answer 1

2

You can use Graphics.MeasureString to measure a string drawn with a specified font. For example, cycle through several font sizes and pick one that fits best into your textbox width.

Another way, which supposedly works better with non-ASCII characters, is TextRenderer.MeasureText. Suggested by this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.