Smart Button
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.
Assembly
| Assembly | Binarymission.WinForms.Controls.BinarySmartButton.dll |
| Root namespace | Binarymission.WinForms.Controls.ButtonControls |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | BinaryMenu, Binarymission.WinForms.Controls.ExtendedMenuControls |
Overview
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
- XP bevel (
IsRenderingThemeon, the default). The button is drawn in the Windows XP style chosen byXPTheme, with an amber edge under the pointer, a darker face while pressed, and a blue (in the olive scheme, green) edge while it is the form's default button. SetDefaultThemetofalsebefore choosingXPTheme: whileDefaultThemeis on, the style follows the Windows colour scheme and a value set inXPThemeis ignored. - Gradient (
IsRenderingThemeoff). The face is a gradient fromStartColortoEndColoratLinearGradientRenderingAngle, inside a one-pixelBorderColoredge. It lightens under the pointer and reverses while pressed (or usesPushedStartColorandPushedEndColor).
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.
Getting started
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
};API reference
Binarymission.WinForms.Controls.ButtonControls
delegate AboutToTheShowContextMenuOnMenuButton | Represents the method that handles OnAboutToTheShowContextMenuOnMenuButton, raised just before a menu button shows its drop-down menu. |
enum ButtonStyles | Specifies whether a SmartButton is a plain push button or a menu button. |
class ContextMenuProperties | The colours and styles a SmartButton menu button uses for its drop-down menu of BinaryMenuItem objects, edited as one expandable group in the Properties window. |
class ContextMenuPropertiesTypeConverter | A type converter that lets the Properties window expand an object into its individual properties. |
class SmartButton | 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. |
enum XPThemes | Specifies the Windows XP colour scheme a SmartButton imitates. |
Binarymission.WinForms.Controls.ButtonControls.SmartButtonControls.Models
enum DropDownMenuRendererThemeKind | Specifies the built-in theme a SmartButton menu button draws its drop-down menu with. |