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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.