I want to display a button with an internationalized label. In English the label perfectly fits the width of the button. In german it does not fit. To calculate dynamically the width I use [...]
using (Graphics cg = this.CreateGraphics())
{
SizeF size = cg.MeasureString(OutlookAddIn4.Resources.Resources.ShowLoginText, this.showLogFile.Font);
this.showLogFile.Width = (int)size.Width+3;
}
[...]
For the String in OutlookAddIn4.Resources.Resources.ShowLoginText="Logfile anzeigen". In calculates 125 pixels. I even added 3 pixels. Padding for the button is set to 0. Why does it calculate the wrong width? this.showLogFile.Font is set to the right Font (Microsoft Sans Serif, 12 pt) (checked this in the debugger).
There is no need to use the underlying
Graphics
object.If you set the button's
AutoSize
property to true, theAutoSizeMode
toGrowAndShrink
, and theAutoEllipsis
to false, it will resize automatically to fit the text.But if you really need to use the
Graphics
objects: