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

OnDrawItem() protected method

protected OnDrawItem ( DrawItemEventArgs e ) : void
e DrawItemEventArgs
return void
            protected override void OnDrawItem(DrawItemEventArgs e)
            {
                base.OnDrawItem(e);

                Graphics graphics = e.Graphics;
                Rectangle bounds = e.Bounds;

                bool selected = ((e.State & DrawItemState.Selected) != 0);
                bool disabled = ((e.State & DrawItemState.Disabled) != 0);

                if (item is CommandBarSeparator)
                {
                    Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height);
                    ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top);
                }
                else
                {
                    this.DrawImage(graphics, bounds, selected, disabled);

                    int width = 6 + imageSize.Width;
                    this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected);

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        if ((this.Text != null) && (this.Text.Length != 0))
                        {
                            Size size = textGraphics.MeasureText(this.Text, font);
                            Point point = new Point();
                            point.X = bounds.X + 3 + imageSize.Width + 6;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, this.Text, point, selected, disabled);
                        }

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

                            Size size = textGraphics.MeasureText(text, font);

                            Point point = new Point();
                            point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, text, point, selected, disabled);
                        }
                    }
                }
            }