ExtendedContextMenuStrip
A ContextMenuStrip that comes ready-styled: pick one of eight
built-in light and dark themes with RendererTheme, or give it colours of your own
through IMenuStripColorTable.
public class ExtendedContextMenuStrip : ContextMenuStrip
Inherits from / implements: ContextMenuStrip
Remarks
Use it anywhere a ContextMenuStrip is used – as a control's
ContextMenuStrip, or shown from code with
Show().
Items, events and keyboard handling are those of the standard menu; only the drawing changes.
Themes
The light themes draw black text on white, the dark themes white text on a charcoal background.
Each has variants with a shaded image margin down the left side (RendererThemeKind.ExtendedLight,
RendererThemeKind.ExtendedDark), orange selection colours on the item under the pointer
(RendererThemeKind.ExtendedSelectionLight, RendererThemeKind.ExtendedSelectionDark),
or a thin line arrow for submenus (RendererThemeKind.LightWithSkinnyMenuExpansionArrow,
RendererThemeKind.DarkWithSkinnyMenuExpansionArrow). Check marks are drawn as a tick in a
square, in the theme's arrow colour.
Your own colours
Pass a colour table to the constructor. It must derive from
ProfessionalColorTable – which supplies the backgrounds, borders and
highlight colours – and implement IMenuStripColorTable, which adds the text, arrow and
check-mark colours and the arrow shape.
Examples
A dark-themed menu for the rows of an orders grid.
using System;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.ExtendedMenuControls;
using Binarymission.WinForms.Controls.ExtendedMenuControls.Models;
ExtendedContextMenuStrip orderMenu = new ExtendedContextMenuStrip
{
RendererTheme = RendererThemeKind.ExtendedSelectionDark
};
orderMenu.Items.Add("Open order", null, (s, e) => OpenSelectedOrder());
orderMenu.Items.Add("Print invoice", null, (s, e) => PrintSelectedInvoice());
orderMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem status = new ToolStripMenuItem("Set status");
status.DropDownItems.Add("Dispatched");
status.DropDownItems.Add("Delivered");
status.DropDownItems.Add("Cancelled");
orderMenu.Items.Add(status);
ordersGrid.ContextMenuStrip = orderMenu;Colours of your own: derive from ProfessionalColorTable and add
IMenuStripColorTable.
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.ExtendedMenuControls.Abstractions;
using Binarymission.WinForms.Controls.ExtendedMenuControls.Models;
public sealed class BrandMenuColours : ProfessionalColorTable, IMenuStripColorTable
{
public override Color ToolStripDropDownBackground => Color.FromArgb(250, 248, 240);
public override Color ImageMarginGradientBegin => Color.FromArgb(240, 232, 210);
public override Color ImageMarginGradientMiddle => Color.FromArgb(240, 232, 210);
public override Color ImageMarginGradientEnd => Color.FromArgb(240, 232, 210);
public override Color MenuItemSelected => Color.FromArgb(0, 102, 102);
public override Color MenuItemBorder => Color.FromArgb(0, 102, 102);
public Color ArrowColor => Color.FromArgb(0, 102, 102);
public Color ArrowColorWhenItemSelected => Color.White;
public Color MenuItemTextColor => Color.FromArgb(40, 40, 40);
public Color MenuItemTextColorWhenItemSelected => Color.White;
public ArrowKind ArrowRenderingStyle => ArrowKind.Skinny;
}
ExtendedContextMenuStrip menu = new ExtendedContextMenuStrip(new BrandMenuColours());See also
Members at a glance
| Constructors | |
|---|---|
ExtendedContextMenuStrip | Initialises a new menu drawn with the RendererThemeKind.Light theme. |
ExtendedContextMenuStrip | Initialises a new menu drawn with the colours of menuStripColorTable, or with the
RendererThemeKind.Light theme when none is given. |
| Properties | |
RendererTheme | Gets or sets the built-in theme the menu is drawn with. |
Constructors
Properties
RendererTheme
Gets or sets the built-in theme the menu is drawn with.
- Value
- One of the
RendererThemeKindvalues. The default isRendererThemeKind.Light.
Remarks
Setting it replaces the menu's renderer at once, including one built from a colour table
passed to the constructor. Reading it on a menu made with a colour table returns
RendererThemeKind.Light, not the custom colours.
Example
// Follow the application's dark mode.
fileMenu.RendererTheme = settings.UseDarkMode ? RendererThemeKind.Dark : RendererThemeKind.Light;