System.Windows.Forms.CommandBarContextMenu.MenuBarItem.OnMeasureItem C# (CSharp) Method

OnMeasureItem() protected method

protected OnMeasureItem ( System.Windows.Forms.MeasureItemEventArgs e ) : void
e System.Windows.Forms.MeasureItemEventArgs
return void
            protected override void OnMeasureItem(MeasureItemEventArgs e)
            {
                base.OnMeasureItem(e);
                Graphics graphics = e.Graphics;

                if (item is CommandBarSeparator)
                {
                    e.ItemWidth = 0;
                    e.ItemHeight = SystemInformation.MenuHeight / 2;
                }
                else
                {
                    Size size = new Size(0, 0);
                    size.Width += 3 + imageSize.Width + 3 + 3 + 1 + 3 + imageSize.Width + 3;
                    size.Height += 3 + imageSize.Height + 3;

                    string text = item.Text;

                    CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                    if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                    {
                        text += TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);
                    }

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        Size textSize = textGraphics.MeasureText(text, font);
                        size.Width += textSize.Width;
                        textSize.Height += 8;
                        if (textSize.Height > size.Height)
                        {
                            size.Height = textSize.Height;
                        }
                    }

                    e.ItemWidth = size.Width;
                    e.ItemHeight = size.Height;
                }
            }