public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e) { StringFormat string_format; Rectangle rect_text = e.Bounds; if (item.Visible == false) return; if (item.MenuBar) string_format = string_format_menu_menubar_text; else string_format = string_format_menu_text; if (item.Separator == true) { int liney = e.Bounds.Y + (e.Bounds.Height / 2); e.Graphics.DrawLine (SystemPens.ControlDark, e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney); e.Graphics.DrawLine (SystemPens.ControlLight, e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1); return; } if (!item.MenuBar) rect_text.X += MenuCheckSize.Width; if (item.BarBreak) { /* Draw vertical break bar*/ Rectangle rect = e.Bounds; rect.Y++; rect.Width = 3; rect.Height = item.MenuHeight - 6; e.Graphics.DrawLine (SystemPens.ControlDark, rect.X, rect.Y , rect.X, rect.Y + rect.Height); e.Graphics.DrawLine (SystemPens.ControlLight, rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height); } Color color_text; Color color_back; Brush brush_text = null; Brush brush_back = null; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) { color_text = ColorHighlightText; color_back = ColorHighlight; brush_text = SystemBrushes.HighlightText; brush_back = SystemBrushes.Highlight; } else { color_text = ColorMenuText; color_back = ColorMenu; brush_text = ResPool.GetSolidBrush (ColorMenuText); brush_back = SystemBrushes.Menu; } /* Draw background */ if (!item.MenuBar) e.Graphics.FillRectangle (brush_back, e.Bounds); if (item.Enabled) { e.Graphics.DrawString (item.Text, e.Font, brush_text, rect_text, string_format); if (item.MenuBar) { Border3DStyle border_style = Border3DStyle.Adjust; if ((item.Status & DrawItemState.HotLight) != 0) border_style = Border3DStyle.RaisedInner; else if ((item.Status & DrawItemState.Selected) != 0) border_style = Border3DStyle.SunkenOuter; if (border_style != Border3DStyle.Adjust) CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu); } } else { if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) { e.Graphics.DrawString (item.Text, e.Font, Brushes.White, new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height), string_format); } e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format); } if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) { string str = item.GetShortCutText (); Rectangle rect = rect_text; rect.X = item.XTab; rect.Width -= item.XTab; if (item.Enabled) { e.Graphics.DrawString (str, e.Font, brush_text, rect, string_format_menu_shortcut); } else { if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) { e.Graphics.DrawString (str, e.Font, Brushes.White, new RectangleF(rect.X + 1, rect.Y + 1, rect.Width, rect_text.Height), string_format_menu_shortcut); } e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect, string_format_menu_shortcut); } } /* Draw arrow */ if (item.MenuBar == false && (item.IsPopup || item.MdiList)) { int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text); if (item.Enabled) { e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ((e.Bounds.Height - cy) /2)); } else { ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back); } bmp.Dispose (); } /* Draw checked or radio */ if (item.MenuBar == false && item.Checked) { Rectangle area = e.Bounds; int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text); e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2)); bmp.Dispose (); } }
public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e) { StringFormat string_format; Rectangle rect_text = e.Bounds; if (item.Visible == false) return; if (item.MenuBar) string_format = string_format_menu_menubar_text; else string_format = string_format_menu_text; if (item.Separator == true) { e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark), e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight), e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1); return; } if (!item.MenuBar) rect_text.X += MenuCheckSize.Width; if (item.BarBreak) { /* Draw vertical break bar*/ Rectangle rect = e.Bounds; rect.Y++; rect.Width = 3; rect.Height = item.MenuHeight - 6; e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark), rect.X, rect.Y , rect.X, rect.Y + rect.Height); e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight), rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height); } Color color_text = ColorMenuText; Color color_back = NiceBackColor; /* Draw background */ Rectangle rect_back = e.Bounds; rect_back.X++; rect_back.Width -=2; if (((e.State & DrawItemState.Selected) == DrawItemState.Selected) || ((e.State & DrawItemState.HotLight) == DrawItemState.HotLight)) { using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (rect_back.X, rect_back.Y), new Point (rect_back.Right, rect_back.Y), Color.White, NormalColor))//NormalColor, Color.White ) ) e.Graphics.FillRectangle (lgbr, rect_back); e.Graphics.DrawRectangle (ResPool.GetPen (BorderColor), rect_back.X, rect_back.Y, rect_back.Width, rect_back.Height - 1); } else { e.Graphics.FillRectangle (ResPool.GetSolidBrush (NiceBackColor), rect_back); } if (item.Enabled) { e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush (color_text), rect_text, string_format); if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) { string str = item.GetShortCutText (); Rectangle rect = rect_text; rect.X = item.XTab; rect.Width -= item.XTab; e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush (color_text), rect, string_format_menu_shortcut); } } else { ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font, Color.Black, rect_text, string_format); } /* Draw arrow */ if (item.MenuBar == false && item.IsPopup || item.MdiList) { int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text); if (item.Enabled) { e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ((e.Bounds.Height - cy) /2)); } else { ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back); } bmp.Dispose (); } /* Draw checked or radio */ if (item.MenuBar == false && item.Checked) { Rectangle area = e.Bounds; int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text); e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2)); bmp.Dispose (); } }
public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar) { item.X = x; item.Y = y; if (item.Visible == false) { item.Width = 0; item.Height = 0; return; } if (item.Separator == true) { item.Height = SEPARATOR_HEIGHT; item.Width = SEPARATOR_MIN_WIDTH; return; } if (item.MeasureEventDefined) { MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index); item.PerformMeasureItem (mi); item.Height = mi.ItemHeight; item.Width = mi.ItemWidth; return; } else { SizeF size; size = dc.MeasureString (item.Text, MenuFont, int.MaxValue, string_format_menu_text); item.Width = (int) size.Width; item.Height = (int) size.Height; if (!menuBar) { if (item.Shortcut != Shortcut.None && item.ShowShortcut) { item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width; size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont); item.Width += MENU_TAB_SPACE + (int) size.Width; } item.Width += 4 + (MenuCheckSize.Width * 2); } else { item.Width += MENU_BAR_ITEMS_SPACE; x += item.Width; } if (item.Height < MenuHeight) item.Height = MenuHeight; } }
public override void DrawMenuItem( MenuItem item, DrawItemEventArgs e ) { StringFormat string_format; Rectangle rect_text = e.Bounds; if ( item.Visible == false ) return; if ( item.MenuBar ) { string_format = string_format_menu_menubar_text; } else { string_format = string_format_menu_text; } if ( item.Separator ) { e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ), e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 1 ); e.Graphics.DrawLine( ResPool.GetPen( Color.White ), e.Bounds.X, e.Bounds.Y + 2, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 2 ); return; } if ( !item.MenuBar ) rect_text.X += MenuCheckSize.Width; if ( item.BarBreak ) { /* Draw vertical break bar*/ Rectangle rect = e.Bounds; rect.Y++; rect.Width = 3; rect.Height = item.MenuHeight - 6; e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ), rect.X, rect.Y , rect.X, rect.Y + rect.Height ); e.Graphics.DrawLine( ResPool.GetPen( ColorControlLight ), rect.X + 1, rect.Y , rect.X + 1, rect.Y + rect.Height ); } Color color_text = ColorMenuText; Color color_back; /* Draw background */ Rectangle rect_back = e.Bounds; rect_back.X++; rect_back.Width -= 2; if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected ) { color_text = ColorHighlightText; color_back = item.MenuBar ? theme_back_color : menu_background_color; using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rect_back.X, rect_back.Y + 1 ), new Point( rect_back.X, rect_back.Bottom - 1 ), menuitem_gradient_first_color, menuitem_gradient_second_color ) ) { e.Graphics.FillRectangle( lgbr, rect_back.X + 1, rect_back.Y + 1, rect_back.Width - 1, rect_back.Height - 1 ); } rect_back.Height--; Pen tmp_pen = ResPool.GetPen( menuitem_border_color ); e.Graphics.DrawLine( tmp_pen, rect_back.X + 1, rect_back.Y, rect_back.Right - 1, rect_back.Y ); e.Graphics.DrawLine( tmp_pen, rect_back.Right, rect_back.Y + 1, rect_back.Right, rect_back.Bottom - 1 ); e.Graphics.DrawLine( tmp_pen, rect_back.Right - 1, rect_back.Bottom, rect_back.X + 1, rect_back.Bottom ); e.Graphics.DrawLine( tmp_pen, rect_back.X, rect_back.Bottom - 1, rect_back.X, rect_back.Y + 1 ); } else { color_text = ColorMenuText; color_back = item.MenuBar ? theme_back_color : menu_background_color; e.Graphics.FillRectangle( ResPool.GetSolidBrush( color_back ), rect_back ); } if ( item.Enabled ) { e.Graphics.DrawString( item.Text, e.Font, ResPool.GetSolidBrush( color_text ), rect_text, string_format ); if ( !item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut ) { string str = item.GetShortCutText( ); Rectangle rect = rect_text; rect.X = item.XTab; rect.Width -= item.XTab; e.Graphics.DrawString( str, e.Font, ResPool.GetSolidBrush( color_text ), rect, string_format_menu_shortcut ); } } else { ControlPaint.DrawStringDisabled( e.Graphics, item.Text, e.Font, Color.Black, rect_text, string_format ); } /* Draw arrow */ if ( item.MenuBar == false && item.IsPopup ) { int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; using ( Bitmap bmp = new Bitmap( cx, cy ) ) { using ( Graphics dc = Graphics.FromImage( bmp ) ) { SmoothingMode old_smoothing_mode = dc.SmoothingMode; dc.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy ); ControlPaint.DrawMenuGlyph( dc, rect_arrow, MenuGlyph.Arrow ); bmp.MakeTransparent( ); if ( item.Enabled ) { e.Graphics.DrawImage( bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) ); } else { ControlPaint.DrawImageDisabled( e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ), color_back ); } dc.SmoothingMode = old_smoothing_mode; } } } /* Draw checked or radio */ if ( item.MenuBar == false && item.Checked ) { Rectangle area = e.Bounds; int cx = MenuCheckSize.Width; int cy = MenuCheckSize.Height; using ( Bitmap bmp = new Bitmap( cx, cy ) ) { using ( Graphics gr = Graphics.FromImage( bmp ) ) { Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy ); if ( item.RadioCheck ) ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Bullet ); else ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Checkmark ); bmp.MakeTransparent( ); e.Graphics.DrawImage( bmp, area.X, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) ); } } } }