How to create custom Button using .NET

No.of Views1191
Bookmarked0 times
Downloads 
Votes0
By  mranjankumar   On  16 Feb 2010 03:02:50
Tag : CSharp , Owner-draw buttons
How to create custom Button using .NET
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Button bar control supporting

  • Keyboard Support
  • Full Designer Support
  • Supports Custom Drawing

This Article Sample Project Source code,

Image Loading

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 array of buttons aligned vertical.

Use the designer to fine tune appearance.

 

Image Loading

 

Image Loading

 

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.

 

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 boundry.
  • SelectedItem - Get current selected button.
  • ShowBorders - Gets or Sets wether 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 wether 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 fiered 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 Calander control to a xml file. fileName is path of xml file to which data will be written. Returns wether save was successful or not.
  • bool ImportAppearance(string fileName) - Loads the color scheme from a xml file. fileName is location of xml file containing color scheme. Returns wether Load was successfull 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 Calander control to default value.Item to be selected..Returns wether item was selected or not.

ThemeProperty

Properties

  • UseTheme - Gets or Sets wether 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 wether 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 Appearence is Empty or not.
  • Item - Gets appearance of BarItem.

Events

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

Methods

  • Assign(Appearance appearance) - Assigns properties of appearance to current object.
  • bool DefaultChanged() - Returns wether property values has 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 has 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 updating this will update Gradient for all State.
  • 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 has been modified.

Methods

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

Known Issues

  • Some Event handler does not get created with proper signature by designer. They Need to be fixed manually.

Version History

  • 2 December 2009: Initial draft of the control

 

Sample Project  code

Download Demo files -58 kb

Download Help files -539 kb

Download Src files -105 kb

Download Lib files -48 kb

 
Sign Up to vote for this article
 
About Author
 
mranjankumar
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-28 Oct 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top