Click here to Skip to main content
15,867,141 members
Articles / Desktop Programming / Windows Forms

ButtonBar Control using .NET

Rate me:
Please Sign up or sign in to vote.
4.95/5 (43 votes)
3 Dec 2009CPOL5 min read 64K   5.5K   104   16
Themed ButtonBar control supporting custom draw with full Designer support
Image 1

Introduction

Buttonbar control provides:

  • Keyboard Support
  • Full Designer Support
  • Custom Drawing Support

Features

ButtonBar control has the following features:

  • 6 pre-defined Themes
  • Supports alpha blend image
  • Full Keyboard support
  • Full Design Time support
  • Supports Saving/Loading of layout colors
  • Supports Disabled back color
  • Supports HotKeys

Using the Code

This control is an array of buttons aligned vertical.

Use the designer to fine tune the appearance.

ButtonBarDesigner.PNG

ButtonBarAppearanceEditor.PNG

Keyboard

  • Enter Key - Select button. Move by arrow key or hover over a button to select and press enter.
  • Down Key - Move to next button.
  • Up Key - Move to previous button.

Points of Interest

ButtonBar

Properties

  • Appearance - Appearance object containing Global Appearance information.
  • ButtonWidth- Width of buttons. Control resizes itself to button.
  • DisableTransparency - Gets or Sets Disabled State Transparency.
  • ImageTransparency - Gets or Sets Background Image transparency.
  • Items - Collections of buttons.
  • Padding - Gets or sets distance of button from control boundary.
  • SelectedItem - Gets current selected button.
  • ShowBorders - Gets or Sets whether borders will be shown or not.
  • Spacing - Gets or Sets distance between buttons.
  • ThemeProperty - Property used to Get or Set which theme should be used. See also ThemeProperty.
  • UseMnemonic - Indicates whether to use shortcut keys or not.

Events

  • BarClick - Occurs when Bar is clicked. This fired when clicked on area other than buttons.
  • CustomDrawBackGround - Occurs when ButtonBar requests drawing. This can be used to implement custom draw.
  • CustomDrawItems - Occurs when BarItem requests drawing. This can be used to implement own drawing.
  • ItemClick - Occurs when a button is pressed. This is also fired when Shortcut key is pressed or Enter key is pressed.
  • ItemsChanged - Occurs when BarItem of Items is changed.
  • ItemsChanging - Occurs when BarItem of Items is changing.
  • ItemsClearing - Occurs when Items is clearing.
  • ItemsInserted - Occurs when BarItem of Items is inserted into collection.
  • ItemsInserting - Occurs when BarItem is being inserted on Items.
  • ItemsRemoved - Occurs when BarItem of Items is removed from collection.
  • ItemsRemoving - Occurs when BarItem is being removed from Items.
  • SelectionChanged - Occurs when Button Selection changes.
  • SelectionChanging - Occurs when Button Selection is about to change.

Methods

  • HitTestInfo HitTest(Point pt) - Performs HitTest for specified point.<code>pt Point of hit. Returns HitTestInfo object containing information related to hit. e.g. Location, button index, etc.
  • HitTestInfo HitTest(int x, int y) - Performs HitTest for specified point.x and y coordinate of Point of hit. Returns HitTestInfo object containing information related to hit. e.g. Location, button index, etc.
  • bool ExportAppearance(string fileName) - Saves current color scheme of the Calendar control to an XML file. fileName is path of XML file to which data will be written. Returns whether save was successful or not.
  • bool ImportAppearance(string fileName) - Loads the color scheme from an XML file. fileName is location of XML file containing color scheme. Returns whether Load was successful or not.
  • EnsureVisibility(int index) - Ensures given item is visible. Scrolls to item if not visible. index is index of item which needs to be shown.
  • State GetButtonState(BarItem barItem) - Gets Current State of button. BarItem of which state is to be determined. State of button.
  • bool SelectItem(BarItem item) - Reset the appearance of Calendar control to default value. Item to be selected. Returns whether item was selected or not.

ThemeProperty

Properties

  • UseTheme - Gets or Sets whether to use predefined theme or custom colors.
  • ColorScheme - Gets or Sets ColorScheme to be applied. Please note: This will not be applicable when UseTheme is set as false.

Events

  • ThemeChanged - Fired when UseTheme or ColorScheme is changed.

Methods

  • bool DefaultChanged() - Returns whether ThemeProperty properties has changed or not.
  • void Reset() - Resets current object to use default value for each property.

Appearance

Properties

  • Bar - Gets appearance of ButtonBar.
  • IsEmpty- Indicates Appearance is Empty or not.
  • Item - Gets appearance of BarItem.

Events

  • AppearanceChanged - Occurs when properties related to drawing have been modified.

Methods

  • Assign(Appearance appearance) - Assigns properties of appearance to current object.
  • bool DefaultChanged() - Returns whether property values have changed or not.
  • Reset() - Resets current appearance to default appearance.

AppearanceBar

Properties

  • AppearanceBorder - Gets border appearance of ButtonBar.
  • BackStyle - Gets background style of ButtonBar.
  • CornerRadius- Gets corner radius of ButtonBar
  • DisabledMask- Gets or Sets disabled mask color of ButtonBar.
  • FocusedBorder - Gets or Sets focused border color of ButtonBar.
  • IsEmpty - Indicates current object is Empty or not.
  • NormalBorder - Gets or Sets Normal border color of ButtonBar.

Events

  • AppearanceChanged - Occurs when properties related to drawing have been modified.

Methods

  • Assign(AppearanceBar app) - Assigns Values of supplied AppearanceBar to current object.app AppearanceBar object whose value is to be assigned.
  • bool DefaultChanged() - Returns wether ThemeProperty properties has changed or not.
  • Reset() - Resets current appearance to default appearance.

AppearanceItem

Properties

  • AppearenceText - Gets AppearenceText of the item.
  • BackStyle - Gets Back style of Item in Normal state.
  • ClickStyle- Gets Back style of Item in Pressed state.
  • DisabledBorder - Gets or Sets border color of Item in Disabled state.
  • DisabledForeGround - Gets or Sets text color of Item in Disabled state.
  • DisabledStyle - Gets Back style of Item in Disabled state.
  • Gradient - Gets or Sets Gradient of Item BackColor. This will update Gradient for all States.
  • HoverBorder - Gets or Sets border color of Item in Hover state.
  • HoverForeGround - Gets or Sets text color of Item in Hover state.
  • HoverStyle - Gets Back style of Item in Hover state.
  • IsEmpty - Indicates current object is Empty or not.
  • NormalBorder - Gets or Sets border color of Item in Normal state.
  • NormalForeGround - Gets or Sets text color of Item in Normal state.
  • SelectedBorder - Gets or Sets border color of Item in Selected state.
  • SelectedForeGround - Gets or Sets text color of Item in Selected state.
  • SelectedHoverStyle - Gets Back style of Item in SelectedHover state.
  • SelectedStyle - Gets Back style of Item in Selected state.

Events

  • AppearanceChanged - Occurs when properties related to drawing have been modified.

Methods

  • Assign(AppearanceItem app) - Assigns properties of app to current object.
  • bool DefaultChanged() - Returns whether ThemeProperty properties has changed or not.
  • Reset() - Resets current appearance to default appearance.

Known Issues

  • Some Event handlers do not get created with proper signature by designer. They need to be fixed manually.

History

  • 2 December 2009: Initial draft of the control

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionNice Pin
User 1327559321-Sep-17 5:55
User 1327559321-Sep-17 5:55 
Questionchanging the image on the button Pin
namg12-Sep-17 14:26
namg12-Sep-17 14:26 
AnswerRe: changing the image on the button Pin
namg12-Sep-17 14:50
namg12-Sep-17 14:50 
Questionnice Pin
BillW337-Nov-11 9:05
professionalBillW337-Nov-11 9:05 
Generalsupport Pin
securigy23-Jun-10 1:54
securigy23-Jun-10 1:54 
General5! Pin
Atanas Palavrov7-Dec-09 22:12
Atanas Palavrov7-Dec-09 22:12 
GeneralA Good work Pin
infinitess7-Dec-09 16:00
infinitess7-Dec-09 16:00 
QuestionOrientation Pin
Ravi Bhavnani5-Dec-09 1:28
professionalRavi Bhavnani5-Dec-09 1:28 
GeneralRe: Orientation Pin
Manish Ranjan Kumar7-Dec-09 2:22
professionalManish Ranjan Kumar7-Dec-09 2:22 
AnswerRe: Orientation Pin
dhirtzbruch13-Dec-10 10:47
dhirtzbruch13-Dec-10 10:47 
GeneralRe: Orientation Pin
Ravi Bhavnani13-Dec-10 10:51
professionalRavi Bhavnani13-Dec-10 10:51 
GeneralFine article, fine control Pin
Marcelo Ricardo de Oliveira4-Dec-09 3:50
mvaMarcelo Ricardo de Oliveira4-Dec-09 3:50 
QuestionMulti-line Text support? Pin
Paul Selormey3-Dec-09 19:45
Paul Selormey3-Dec-09 19:45 
AnswerRe: Multi-line Text support? Pin
Manish Ranjan Kumar3-Dec-09 21:33
professionalManish Ranjan Kumar3-Dec-09 21:33 
GeneralRe: Multi-line Text support? Pin
Paul Selormey3-Dec-09 21:39
Paul Selormey3-Dec-09 21:39 
AnswerRe: Multi-line Text support? Pin
Manish Ranjan Kumar4-Dec-09 1:17
professionalManish Ranjan Kumar4-Dec-09 1:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.