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.
Asked
Active
Viewed 560 times
1 Answers
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.

Community
- 1
- 1

Victor Zakharov
- 25,801
- 18
- 85
- 151