Is there any way to calculate text width based on available height in c# on windows forms?
Edit: I have the font size. I want to calculate the minimum width required for drawing the text considering the line could be wrapped.
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.
what you can do is to measure a string in a default size with this method:
(g is a Graphics Object)
you scale the fontsize depending on the proportion measuredHeight to availableHeight. After you can remeasure the string with the height of the available area
or you just measure it to get the proportions and calculated the expected width like that: