In the process of translating an application with C# + Winforms, I need to change a button's text depending on the language.
My problem is the following :
Let's say I want to translate a button from "Hi all!" to "Bonjour tout le monde" !
As you can guess, the button's size won't be the same if I enter english text or french one... My question is "simple", how can I manage to resize the button on the fly so the text fits its content in the button ?
So far I got something like that !
[Hi all!]
[Bonjour]
Set a padding to the container, it will make it larger depending on how much text is added. For example: padding: 4px 10px; So in your case, remove the width from your <a> selector and add the padding.
Tip: Use pixels if you want to set a fixed width and use percent for responsive buttons (e.g. 50% of its parent element).
There's absolutely no need to use the underlying Graphics
object as the other posters have said.
If you set the button's AutoSize
property to true, the AutoSizeMode
to GrowAndShrink
, and the AutoEllipsis
to false, it will resize automatically to fit the text.
That being said, you may need to make several layout adjustments to make this change fit into your UI. You can adjust the button's padding to add space around the text, and you may want to place your buttons in a TableLayoutPanel
(or something) to stop them from overlapping when they resize.
Edit:
@mastro pointed out that: AutoEllipsis
is only valid when AutoSize
is false
(As explained in the documentation), so it can be safely ignored as long as the other three properties are set correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With