Reputation: 10267
I am dynamically creating various Windows controls where the user supplies the text that will display on a button, alongside a checkbox, inside a label, etc.
With the default Windows font, is there a "good-enough" (this is just a mockup, anyway - doesn't have to always be perfect) formula to determine what the width of the control should be relative to the width of the text? e.g., should it be something like:
Control.Width = text.Length * 3
...or...???
Upvotes: 0
Views: 93
Reputation: 15151
You can always measure the text size with TextRenderer.MeasureText. Once you have how much wide the string will be you just need to add some extra width to allow control border's and else.
Upvotes: 3
Reputation: 23793
There is no need to do this manually.
Setting the AutoSize
property to true
on your Control will do this for you.
Upvotes: 2