private void UpdateSize()
{
if (this.style == CommandBarStyle.Menu)
{
int fontHeight = Font.Height;
using (Graphics graphics = this.CreateGraphics())
{
using (TextGraphics textGraphics = new TextGraphics(graphics))
{
foreach (CommandBarItem item in items)
{
Size textSize = textGraphics.MeasureText(item.Text, this.Font);
if (fontHeight < textSize.Height)
{
fontHeight = textSize.Height;
}
}
}
}
NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONSIZE, 0, (fontHeight << 16) | 0xffff);
}
Size size = new Size(0, 0);
for (int i = 0; i < items.Count; i++)
{
NativeMethods.RECT rect = new NativeMethods.RECT();
NativeMethods.SendMessage(Handle, NativeMethods.TB_GETRECT, i, ref rect);
int height = rect.bottom - rect.top;
if (height > size.Height)
{
size.Height = height;
}
size.Width += rect.right - rect.left;
}
this.Size = size;
}