Click here to Skip to main content
Click here to Skip to main content

ButtonBar Control using .NET

, 3 Dec 2009
Rate this:
Please Sign up or sign in to vote.
Themed ButtonBar control supporting custom draw with full Designer support

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.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)

About the Author

Manish Ranjan Kumar
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
Questionnice PinmemberCIDev7-Nov-11 9:05 
Generalsupport Pinmembersecurigy23-Jun-10 1:54 
General5! PinmemberAtanas Palavrov7-Dec-09 22:12 
GeneralA Good work Pinmemberinfinitess7-Dec-09 16:00 
QuestionOrientation PinmemberRavi Bhavnani5-Dec-09 1:28 
GeneralRe: Orientation PinmemberManish Ranjan Kumar7-Dec-09 2:22 
AnswerRe: Orientation Pinmemberdhirtzbruch13-Dec-10 10:47 
GeneralRe: Orientation PinmemberRavi Bhavnani13-Dec-10 10:51 
GeneralFine article, fine control PinmemberMarcelo Ricardo de Oliveira4-Dec-09 3:50 
QuestionMulti-line Text support? PinmemberPaul Selormey3-Dec-09 19:45 
AnswerRe: Multi-line Text support? PinmemberManish Ranjan Kumar3-Dec-09 21:33 
GeneralRe: Multi-line Text support? PinmemberPaul Selormey3-Dec-09 21:39 
AnswerRe: Multi-line Text support? PinmemberManish Ranjan Kumar4-Dec-09 1:17 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 3 Dec 2009
Article Copyright 2009 by Manish Ranjan Kumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid