HypernovaDesktop Components · docs
Binarymission
WinForms › Smart Button › SmartButton

SmartButton

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.ButtonControls

A push button with a crisp, bevelled Windows XP look in blue, olive or silver – or a gradient in colours of your own – that can show an icon with its full alpha channel and can open a drop-down menu of commands.

public partial class SmartButton : System.Windows.Forms.Control, IButtonControl

Inherits from / implements: System.Windows.Forms.Control, IButtonControl

Remarks

Use it wherever a Button would go: it raises Control.Click, takes a DialogResult, and implements IButtonControl, so it can be a form's Form.AcceptButton or Form.CancelButton. Space clicks it while it has the focus, and an ampersand in Text gives it an Alt+letter shortcut.

Two looks

A disabled button is always drawn with the grey XP bevel, with grey text and a greyed image.

Text and image

Text is centred, in ForeColor, and trimmed with an ellipsis when it does not fit; UseCustomTextStringFormat and TextStringFormat lay it out your way. Icon shows an icon with its alpha channel intact (soft shadows and edges); Image shows a bitmap, with TransparentColor made see-through. Either sits at the left of the text, or in the middle when there is no text.

Menu button

With ButtonStyle set to ButtonStyles.MenuButton, the button shows a separator and a down arrow at its right, and a click opens a menu under it instead of raising Control.Click. The menu is the button's Control.ContextMenuStrip when one is set; otherwise it is a ContextMenu built from DropDownMenuItems, drawn with ContextMenuProperties when its items are BinaryMenuItem objects and UseCustomDefinedPropertiesForRenderingContextMenu is on. Handle OnAboutToTheShowContextMenuOnMenuButton to update or cancel the menu as it opens.

The button has a size of 10 by 10 pixels when created; give it a Control.Size.

Examples

A "Save" button in the default blue style that is the form's accept button, and an "Export" menu button beside it.

using System;
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.ButtonControls;
using Binarymission.WinForms.Controls.ButtonControls.SmartButtonControls.Models;

public class InvoiceForm : Form
{
    public InvoiceForm()
    {
        Text = "Invoice INV-20431";

        SmartButton save = new SmartButton
        {
            Text = "&Save",
            Location = new Point(16, 16),
            Size = new Size(96, 30),
            Icon = new Icon("save.ico", 16, 16)
        };
        save.Click += (sender, e) => SaveInvoice();

        SmartButton export = new SmartButton
        {
            Text = "Export",
            Location = new Point(124, 16),
            Size = new Size(110, 30),
            ButtonStyle = ButtonStyles.MenuButton,
            DropDownMenuItems = new MenuItem[]
            {
                new MenuItem("As PDF...", (s, e) => ExportInvoice("pdf")),
                new MenuItem("As Excel workbook...", (s, e) => ExportInvoice("xlsx")),
                new MenuItem("As CSV...", (s, e) => ExportInvoice("csv"))
            }
        };

        Controls.Add(save);
        Controls.Add(export);
        AcceptButton = save;
    }

    private void SaveInvoice() { /* ... */ }
    private void ExportInvoice(string format) { /* ... */ }
}

The same button drawn as a gradient in the application's own colours.

SmartButton approve = new SmartButton
{
    Text = "Approve",
    Size = new Size(110, 32),
    IsRenderingTheme = false,
    StartColor = Color.FromArgb(46, 160, 67),
    EndColor = Color.FromArgb(28, 110, 44),
    LinearGradientRenderingAngle = 90f,
    BorderColor = Color.FromArgb(20, 80, 32),
    ForeColor = Color.White
};

See also

Members at a glance

Constructors
SmartButtonInitialises a new button in the blue XP style, with black text, ready to be given a size and text.
Properties
BorderColorGets or sets the colour of the one-pixel edge round the button, when it is drawn as a gradient.
ButtonStyleGets or sets whether the button is a plain push button or a menu button that opens a drop-down menu.
ContextMenuPropertiesGets or sets the colours and rendering style of the drop-down menu, used while UseCustomDefinedPropertiesForRenderingContextMenu is on.
DefaultThemeGets or sets whether the XP style follows the Windows colour scheme rather than XPTheme.
DialogResultGets or sets the result a click gives the form the button is on.
DrawFocusRectangleGets or sets whether a dotted focus rectangle is drawn inside the button while it has the keyboard focus.
DrawMenuButtonSeparatorGets or sets whether a menu button draws a separator line between its text and its arrow.
DropDownArrowMarkColorGets or sets the colour of the down arrow at the right of a menu button.
DropDownMenuItemsGets or sets the commands a menu button lists in its drop-down menu.
DropDownMenuItemsGets or sets the commands a menu button lists in its drop-down menu.
DropDownMenuRendererThemeGets or sets the built-in theme for the drop-down menu that a menu button builds from DropDownMenuItems.
EndColorGets or sets the colour the face's gradient ends with, when the button is drawn as a gradient.
ForeColorGets or sets the colour of the button's text.
IconGets or sets an icon to show on the button, drawn with its alpha channel so soft edges and shadows look right.
ImageGets or sets a bitmap to show on the button.
IsRenderingThemeGets or sets whether the button is drawn with the Windows XP bevel or with your own gradient.
LinearGradientRenderingAngleGets or sets the direction of the face's gradient, when the button is drawn as a gradient.
MenuButtonSeparatorColorGets or sets the colour of the separator line between a menu button's text and its arrow.
MenuButtonSeparatorLineHeightGets or sets the height of the separator line between a menu button's text and its drop-down arrow.
MenuStripColorTableGets or sets your own colours for the drop-down menu that a menu button builds from DropDownMenuItems.
PushedEndColorGets or sets the colour the face's gradient ends with while the button is pressed or its menu is open.
PushedStartColorGets or sets the colour the face's gradient starts from while the button is pressed or its menu is open.
ShowDropDownArrowGets or sets whether a menu button shows its down arrow.
StartColorGets or sets the colour the face's gradient starts from, when the button is drawn as a gradient.
TextGets or sets the caption shown on the button.
TextStringFormatGets or sets the alignment, trimming and wrapping used for the caption when UseCustomTextStringFormat is on.
TransparentColorGets or sets the colour in Image that is made see-through, so the button's face shows through it.
UseCustomDefinedPropertiesForRenderingContextMenuGets or sets whether the drop-down menu is drawn with the colours in ContextMenuProperties.
UseCustomTextStringFormatGets or sets whether the caption is laid out with TextStringFormat rather than centred.
UseUserDefinedColorForArrowMarkGets or sets whether a menu button's arrow keeps the colour you give it rather than following XPTheme.
UseUserDefinedColorForMenuButtonSeparatorGets or sets whether a menu button's separator line keeps the colour you give it rather than following XPTheme.
XPThemeGets or sets which Windows XP colour scheme the bevelled button is drawn in.
Methods
DisposeReleases the drawing resources the button holds.
NotifyDefaultTells the button whether it is the form's default button, so it can draw itself as one.
OnClickHandles a click: a menu button raises OnAboutToTheShowContextMenuOnMenuButton and opens its menu; any other button applies its DialogResult and raises the Control.Click event.
OnDpiChangedAfterParentRepaints the button when it moves to a display with a different scale factor.
OnEnterRaises the Control.Enter event and repaints the button.
OnHandleCreatedRaises the Control.HandleCreated event, sets the button's outline for the display, and applies the theme and separator colour.
OnKeyDownRaises the Control.KeyDown event, showing the button pressed while Enter or Space is held down.
OnKeyUpRaises the Control.KeyUp event after releasing the pressed look, and clicks the button when the key is Space.
OnLeaveRaises the Control.Leave event and repaints the button.
OnMouseDownRaises the Control.MouseDown event, and on a left-button press shows the button pressed and gives it the focus.
OnMouseEnterRaises the Control.MouseEnter event and shows the button's hover look.
OnMouseLeaveRaises the Control.MouseLeave event and returns the button to its normal look.
OnMouseMoveRaises the Control.MouseMove event and shows the button pressed while the left button is held down over it.
OnMouseUpRaises the Control.MouseUp event and releases the pressed look of a plain button; a menu button stays pressed while its menu is open.
OnPaintDraws the button – its bevel or gradient, image, text, focus rectangle and, on a menu button, the separator and arrow – then raises the Control.Paint event.
OnParentChangedRaises the Control.ParentChanged event after matching the button's background to its parent.
OnSizeChangedRaises the Control.SizeChanged event after fitting the outline, the image position and MenuButtonSeparatorLineHeight to the new size.
OnSystemColorsChangedRaises the Control.SystemColorsChanged event and, while DefaultTheme is on, picks up a change of Windows colour scheme.
OnTextChangedRaises the Control.TextChanged event after re-laying out the caption and image.
PerformClickClicks the button from code, as if the user had clicked it.
ProcessMnemonicClicks the button when its Alt+letter shortcut is pressed.
WndProcProcesses Windows messages, and returns a menu button to its unpressed look when its menu closes.
Events
OnAboutToTheShowContextMenuOnMenuButtonOccurs when a menu button has been clicked, just before its drop-down menu opens.

Constructors

SmartButton

public SmartButton()

Initialises a new button in the blue XP style, with black text, ready to be given a size and text.

Properties

BorderColor

public Color BorderColor

Gets or sets the colour of the one-pixel edge round the button, when it is drawn as a gradient.

Value
The default is Color.Black.
Remarks

Used only while IsRenderingTheme is false. The edge is one logical pixel wide.

ButtonStyle

public ButtonStyles ButtonStyle

Gets or sets whether the button is a plain push button or a menu button that opens a drop-down menu.

Value
ButtonStyles.Normal or ButtonStyles.MenuButton. The default is ButtonStyles.Normal.
Default
ButtonStyles.Normal
Remarks

A menu button draws a separator and a down arrow at its right and, when clicked, raises OnAboutToTheShowContextMenuOnMenuButton and opens its menu – the Control.ContextMenuStrip if one is set, otherwise one built from DropDownMenuItems. It does not raise Control.Click.

Setting it to ButtonStyles.MenuButton turns ShowDropDownArrow back on, so set that afterwards to hide the arrow.

ContextMenuProperties

public ContextMenuProperties ContextMenuProperties

Gets or sets the colours and rendering style of the drop-down menu, used while UseCustomDefinedPropertiesForRenderingContextMenu is on.

Value
A ContextMenuProperties with its own defaults, to begin with.

DefaultTheme

public bool DefaultTheme

Gets or sets whether the XP style follows the Windows colour scheme rather than XPTheme.

Value
true to follow Windows; the default is true.
Remarks

While this is on, a value set in XPTheme is ignored. The Windows XP Olive Green and Silver schemes give XPThemes.OliveGreen and XPThemes.Silver; every other scheme, including those of current Windows versions, gives XPThemes.Blue.

To choose the style yourself, set this to false first and then set XPTheme.

Example
saveButton.DefaultTheme = false;
saveButton.XPTheme = XPThemes.Silver;

DialogResult

public System.Windows.Forms.DialogResult DialogResult

Gets or sets the result a click gives the form the button is on.

Value
One of the DialogResult values. The default is None, which leaves the form alone.
Remarks

When it is not None, a click sets the form's DialogResult, which closes a form shown with Form.ShowDialog. A value outside the enumeration is ignored. Not applied by a ButtonStyles.MenuButton.

Example
okButton.DialogResult = DialogResult.OK;
cancelButton.DialogResult = DialogResult.Cancel;
CancelButton = cancelButton;

if (new CustomerDetailsForm().ShowDialog() == DialogResult.OK)
{
    RefreshCustomerList();
}

DrawFocusRectangle

public bool DrawFocusRectangle

Gets or sets whether a dotted focus rectangle is drawn inside the button while it has the keyboard focus.

Value
true to draw it; the default is false.
Default
false
Remarks

Turn it on for forms people move through with the Tab key. Not drawn on a disabled button.

DrawMenuButtonSeparator

public bool DrawMenuButtonSeparator

Gets or sets whether a menu button draws a separator line between its text and its arrow.

Value
true to draw the separator; the default is true.
Remarks

The line is two logical pixels wide, in MenuButtonSeparatorColor, and MenuButtonSeparatorLineHeight high. Without it the caption may use the full width of the button.

DropDownArrowMarkColor

public Color DropDownArrowMarkColor

Gets or sets the colour of the down arrow at the right of a menu button.

Value
The arrow colour. The default is Color.RoyalBlue, the blue XP scheme's colour.
Remarks

A disabled button draws the arrow in the system grey text colour. To have the arrow follow XPTheme instead, set UseUserDefinedColorForArrowMark to false.

See also

DropDownMenuItems

public MenuItem[] DropDownMenuItems

Gets or sets the commands a menu button lists in its drop-down menu.

Value
MenuItem objects – BinaryMenuItem ones for the styled menu – or null. The default is null. A "-" item is a separator.
Remarks

Used when ButtonStyle is ButtonStyles.MenuButton and the button has no Control.ContextMenuStrip. Each click builds a ContextMenu from these items and opens it under the button. Handle each item's own MenuItem.Click to run its command.

Set it from code; it is not shown in the Properties window. A menu button that has neither items nor a Control.ContextMenuStrip throws when clicked.

Example
MenuItem replyAll = new MenuItem("Reply all");
replyAll.Click += (s, e) => ReplyToAll();

replyButton.ButtonStyle = ButtonStyles.MenuButton;
replyButton.DropDownMenuItems = new MenuItem[]
{
    new MenuItem("Reply", (s, e) => Reply()),
    replyAll,
    new MenuItem("-"),
    new MenuItem("Forward", (s, e) => Forward())
};

DropDownMenuItems

public ToolStripItem[] DropDownMenuItems

Gets or sets the commands a menu button lists in its drop-down menu.

Value
The menu items, such as ToolStripMenuItem and ToolStripSeparator objects, or null. The default is null.
Remarks

Used when ButtonStyle is ButtonStyles.MenuButton and the button has no Control.ContextMenuStrip. Each click builds a fresh menu from these items, drawn with MenuStripColorTable or DropDownMenuRendererTheme, and opens it under the button. Handle each item's own ToolStripItem.Click to run its command.

Set it from code; it is not shown in the Properties window. A menu button that has neither items nor a Control.ContextMenuStrip throws when clicked.

Example
ToolStripMenuItem replyAll = new ToolStripMenuItem("Reply all");
replyAll.Click += (s, e) => ReplyToAll();

replyButton.ButtonStyle = ButtonStyles.MenuButton;
replyButton.DropDownMenuItems = new ToolStripItem[]
{
    new ToolStripMenuItem("Reply", null, (s, e) => Reply()),
    replyAll,
    new ToolStripSeparator(),
    new ToolStripMenuItem("Forward", null, (s, e) => Forward())
};

DropDownMenuRendererTheme

public DropDownMenuRendererThemeKind DropDownMenuRendererTheme

Gets or sets the built-in theme for the drop-down menu that a menu button builds from DropDownMenuItems.

Value
One of the DropDownMenuRendererThemeKind values. The default is DropDownMenuRendererThemeKind.Custom, which draws the menu in the light theme.
Remarks

Ignored while MenuStripColorTable is set, and when the button has a Control.ContextMenuStrip. Takes effect the next time the menu opens.

Example
exportButton.ButtonStyle = ButtonStyles.MenuButton;
exportButton.DropDownMenuRendererTheme = DropDownMenuRendererThemeKind.ExtendedSelectionDark;

EndColor

public Color EndColor

Gets or sets the colour the face's gradient ends with, when the button is drawn as a gradient.

Value
The default is Color.White.
Remarks

Used only while IsRenderingTheme is false.

See also

ForeColor

public new Color ForeColor

Gets or sets the colour of the button's text.

Value
The text colour. The default is SystemColors.ControlText.
Default
ControlText"), System.ComponentModel.RefreshProperties(RefreshProperties.Repaint
Remarks

A disabled button draws its text in the system grey text colour.

Icon

public Icon Icon

Gets or sets an icon to show on the button, drawn with its alpha channel so soft edges and shadows look right.

Value
The icon, or null for none. The default is null.
Default
null), System.ComponentModel.RefreshProperties(RefreshProperties.Repaint
Remarks

The icon is drawn at its own size, 7 logical pixels from the left edge and centred vertically, with the text to its right – or in the middle of the button when Text is empty. On a disabled button it is drawn greyed.

A button shows an icon or an Image, not both: setting an icon clears Image.

Example
printButton.Icon = new Icon(Properties.Resources.PrinterIcon, 24, 24);
printButton.Text = "Print";

Image

public Image Image

Gets or sets a bitmap to show on the button.

Value
The image, or null for none. The default is null.
Default
null), System.ComponentModel.RefreshProperties(RefreshProperties.Repaint
Exceptions
System.InvalidCastException
The image is not a Bitmap, such as a Metafile.
Remarks

The image must be a Bitmap. Pixels of TransparentColor are made see-through, and the button keeps its own copy. The pixels are also made see-through in the bitmap you pass, so pass a copy if you use that bitmap elsewhere.

The image is placed as Icon is, and greyed on a disabled button. A button shows an image or an Icon, not both: setting an image clears Icon. For images with soft, semi-transparent edges, use Icon.

IsRenderingTheme

public bool IsRenderingTheme

Gets or sets whether the button is drawn with the Windows XP bevel or with your own gradient.

Value
true for the XP bevel in XPTheme; false for a gradient from StartColor to EndColor with a BorderColor edge. The default is true.
Remarks

A disabled button is drawn with the grey XP bevel whatever this is set to.

LinearGradientRenderingAngle

public float LinearGradientRenderingAngle

Gets or sets the direction of the face's gradient, when the button is drawn as a gradient.

Value
The angle in degrees, measured clockwise from the left-to-right direction: 0 runs left to right, 90 top to bottom. The default is 90.
Remarks

Used only while IsRenderingTheme is false.

MenuButtonSeparatorColor

public Color MenuButtonSeparatorColor

Gets or sets the colour of the separator line between a menu button's text and its arrow.

Value
The separator colour. Once the button has been created on screen the default is Color.Blue.
Remarks

A disabled button draws the separator in the system grey text colour. To have the separator follow XPTheme instead, set UseUserDefinedColorForMenuButtonSeparator to false.

See also

MenuButtonSeparatorLineHeight

public int MenuButtonSeparatorLineHeight

Gets or sets the height of the separator line between a menu button's text and its drop-down arrow.

Value
The height in logical pixels, centred vertically in the button, or -1 for half the button's height. The default is -1.
Remarks

When the button is resized, a height that no longer fits – more than the button's height less 4 logical pixels – is reduced to fit. Drawn only on a ButtonStyles.MenuButton with DrawMenuButtonSeparator on.

See also

MenuStripColorTable

public IMenuStripColorTable MenuStripColorTable

Gets or sets your own colours for the drop-down menu that a menu button builds from DropDownMenuItems.

Value
A colour table, or null to use DropDownMenuRendererTheme. The default is null.
Remarks

The object must derive from ProfessionalColorTable as well as implement IMenuStripColorTable; it is taken when the menu opens, so a change shows the next time. When set, it wins over DropDownMenuRendererTheme.

Not used when the button has a Control.ContextMenuStrip, which is shown with its own renderer.

PushedEndColor

public Color PushedEndColor

Gets or sets the colour the face's gradient ends with while the button is pressed or its menu is open.

Value
The default is Color.Empty, which uses StartColor – so a pressed button shows its own gradient reversed.
Remarks

Used only while IsRenderingTheme is false.

See also

PushedStartColor

public Color PushedStartColor

Gets or sets the colour the face's gradient starts from while the button is pressed or its menu is open.

Value
The default is Color.Empty, which uses EndColor – so a pressed button shows its own gradient reversed.
Remarks

Used only while IsRenderingTheme is false.

See also

ShowDropDownArrow

public bool ShowDropDownArrow

Gets or sets whether a menu button shows its down arrow.

Value
true to show the arrow; the default is true.
Default
true), System.ComponentModel.RefreshProperties(RefreshProperties.Repaint
Remarks

A value set while ButtonStyle is not ButtonStyles.MenuButton is ignored, and setting ButtonStyle to ButtonStyles.MenuButton turns the arrow back on – so set this after ButtonStyle.

StartColor

public Color StartColor

Gets or sets the colour the face's gradient starts from, when the button is drawn as a gradient.

Value
The default is Color.Silver.
Remarks

Used only while IsRenderingTheme is false. The gradient runs in the direction of LinearGradientRenderingAngle. Under the pointer the gradient is lightened by about a fifth towards white.

See also

Text

public override string Text

Gets or sets the caption shown on the button.

Value
The caption. An ampersand before a letter ("&Save") underlines it and makes Alt+letter click the button.
Remarks

The caption is centred in the space beside any image, in ForeColor, and is trimmed with an ellipsis when it does not fit, unless UseCustomTextStringFormat says otherwise.

TextStringFormat

public StringFormat TextStringFormat

Gets or sets the alignment, trimming and wrapping used for the caption when UseCustomTextStringFormat is on.

Value
A StringFormat, or null. The default is null.
Remarks

The button reads a copy at every repaint, so changes made to the object later are picked up. Ampersand shortcuts are always shown underlined, whatever the format says.

Example
nextButton.TextStringFormat = new StringFormat
{
    Alignment = StringAlignment.Near,
    LineAlignment = StringAlignment.Center
};
nextButton.UseCustomTextStringFormat = true;

TransparentColor

public Color TransparentColor

Gets or sets the colour in Image that is made see-through, so the button's face shows through it.

Value
The colour to remove, such as the magenta background of a toolbar bitmap. The default is Color.Empty, which removes nothing.
Remarks

Applies to the current image straight away and to any image set later. It has no effect on Icon, which carries its own transparency.

Example
refreshButton.TransparentColor = Color.Magenta;
refreshButton.Image = Properties.Resources.Refresh16;

UseCustomDefinedPropertiesForRenderingContextMenu

public bool UseCustomDefinedPropertiesForRenderingContextMenu

Gets or sets whether the drop-down menu is drawn with the colours in ContextMenuProperties.

Value
The default is false.
Remarks

Applies when the menu is built from DropDownMenuItems made of BinaryMenuItem objects. Each time the menu opens, the properties are copied into the shared BinaryMenuItemManager, so they apply to every BinaryMenuItem in the application from then on.

UseCustomTextStringFormat

public bool UseCustomTextStringFormat

Gets or sets whether the caption is laid out with TextStringFormat rather than centred.

Value
true to use TextStringFormat; the default is false, which centres the caption both ways and trims it at a word with an ellipsis.
Remarks

Has no effect until TextStringFormat is set.

UseUserDefinedColorForArrowMark

public bool UseUserDefinedColorForArrowMark

Gets or sets whether a menu button's arrow keeps the colour you give it rather than following XPTheme.

Value
true to keep DropDownArrowMarkColor; false to colour the arrow to match the XP scheme (royal blue, olive or black). The default is true.
Remarks

Setting it to false recolours the arrow straight away.

UseUserDefinedColorForMenuButtonSeparator

public bool UseUserDefinedColorForMenuButtonSeparator

Gets or sets whether a menu button's separator line keeps the colour you give it rather than following XPTheme.

Value
true to keep MenuButtonSeparatorColor; false to colour the separator to match the XP scheme (royal blue, olive or black). The default is true.
Remarks

While this is on, the separator colour is re-applied when the button is created on screen and when the system colours change.

XPTheme

public XPThemes XPTheme

Gets or sets which Windows XP colour scheme the bevelled button is drawn in.

Value
One of the XPThemes values. The default is XPThemes.Blue.
Remarks

Ignored while DefaultTheme is true (the default) – set that to false first. Used only while IsRenderingTheme is on.

When UseUserDefinedColorForMenuButtonSeparator or UseUserDefinedColorForArrowMark is off, the separator and arrow change to the scheme's colour: royal blue, olive or black.

Methods

Dispose

protected override void Dispose(bool disposing)

Releases the drawing resources the button holds.

Parameters
disposing
true when called from Dispose(); false when called from a finaliser.

NotifyDefault

public void NotifyDefault(bool value)

Tells the button whether it is the form's default button, so it can draw itself as one.

Parameters
value
true to draw the default button's accent – a blue (in the olive scheme, green) edge on the XP bevel; false to draw it as an ordinary button.
Remarks

The form calls this itself as the focus moves and when the button is its Form.AcceptButton; there is seldom a reason to call it from code.

OnClick

protected override void OnClick(System.EventArgs e)

Handles a click: a menu button raises OnAboutToTheShowContextMenuOnMenuButton and opens its menu; any other button applies its DialogResult and raises the Control.Click event.

Parameters
e
The event data.
Remarks

A derived class that overrides this should call the base implementation, or the menu will not open and Control.Click will not be raised.

OnDpiChangedAfterParent

protected override void OnDpiChangedAfterParent(EventArgs e)

Repaints the button when it moves to a display with a different scale factor.

Parameters
e
The event data.

OnEnter

protected override void OnEnter(System.EventArgs e)

Raises the Control.Enter event and repaints the button.

Parameters
e
The event data.

OnHandleCreated

protected override void OnHandleCreated(EventArgs e)

Raises the Control.HandleCreated event, sets the button's outline for the display, and applies the theme and separator colour.

Parameters
e
The event data.

OnKeyDown

protected override void OnKeyDown(KeyEventArgs ke)

Raises the Control.KeyDown event, showing the button pressed while Enter or Space is held down.

Parameters
ke
The key that was pressed.

OnKeyUp

protected override void OnKeyUp(KeyEventArgs ke)

Raises the Control.KeyUp event after releasing the pressed look, and clicks the button when the key is Space.

Parameters
ke
The key that was released.

OnLeave

protected override void OnLeave(System.EventArgs e)

Raises the Control.Leave event and repaints the button.

Parameters
e
The event data.

OnMouseDown

protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)

Raises the Control.MouseDown event, and on a left-button press shows the button pressed and gives it the focus.

Parameters
e
The pointer position and buttons.

OnMouseEnter

protected override void OnMouseEnter(EventArgs e)

Raises the Control.MouseEnter event and shows the button's hover look.

Parameters
e
The event data.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises the Control.MouseLeave event and returns the button to its normal look.

Parameters
e
The event data.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Raises the Control.MouseMove event and shows the button pressed while the left button is held down over it.

Parameters
e
The pointer position and buttons.

OnMouseUp

protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)

Raises the Control.MouseUp event and releases the pressed look of a plain button; a menu button stays pressed while its menu is open.

Parameters
e
The pointer position and buttons.

OnPaint

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)

Draws the button – its bevel or gradient, image, text, focus rectangle and, on a menu button, the separator and arrow – then raises the Control.Paint event.

Parameters
e
The graphics surface and clip rectangle to paint.
Remarks

A handler of Control.Paint draws on top of the finished button.

OnParentChanged

protected override void OnParentChanged(System.EventArgs e)

Raises the Control.ParentChanged event after matching the button's background to its parent.

Parameters
e
The event data.
Remarks

The button's Control.BackColor is set to a fully transparent version of the parent's background colour, so the corners outside the bevel show the parent. The button also calls this on every resize, so Control.ParentChanged is raised then too. When the button is removed from its parent nothing is done and the event is not raised.

OnSizeChanged

protected override void OnSizeChanged(System.EventArgs e)

Raises the Control.SizeChanged event after fitting the outline, the image position and MenuButtonSeparatorLineHeight to the new size.

Parameters
e
The event data.

OnSystemColorsChanged

protected override void OnSystemColorsChanged(EventArgs e)

Raises the Control.SystemColorsChanged event and, while DefaultTheme is on, picks up a change of Windows colour scheme.

Parameters
e
The event data.

OnTextChanged

protected override void OnTextChanged(EventArgs e)

Raises the Control.TextChanged event after re-laying out the caption and image.

Parameters
e
The event data.

PerformClick

public void PerformClick()

Clicks the button from code, as if the user had clicked it.

Remarks

Does nothing while the button is hidden or disabled. A ButtonStyles.MenuButton opens its menu; any other button raises Control.Click and applies its DialogResult.

ProcessMnemonic

protected override bool ProcessMnemonic(char charCode)

Clicks the button when its Alt+letter shortcut is pressed.

Parameters
charCode
The character typed with Alt.
Returns

true when charCode is the letter after the ampersand in Text and the button was clicked; otherwise the result of the base implementation.

WndProc

protected override void WndProc(ref Message m)

Processes Windows messages, and returns a menu button to its unpressed look when its menu closes.

Parameters
m
The message to process.

Events

OnAboutToTheShowContextMenuOnMenuButton

public event AboutToTheShowContextMenuOnMenuButton OnAboutToTheShowContextMenuOnMenuButton

Occurs when a menu button has been clicked, just before its drop-down menu opens.

Remarks

Raised only when ButtonStyle is ButtonStyles.MenuButton. Use it to enable, disable or fill the menu items for the current state, or set the ref argument to true to keep the menu closed.

A menu button raises this in place of Control.Click.

Example
export.OnAboutToTheShowContextMenuOnMenuButton += (object sender, ref bool cancel) =>
{
    if (invoiceGrid.SelectedRows.Count == 0)
    {
        MessageBox.Show("Choose an invoice to export first.");
        cancel = true;
    }
};