Click here to Skip to main content
15,790,565 members
Articles / Programming Languages / C#


Rate me:
Please Sign up or sign in to vote.
4.38/5 (16 votes)
12 Jan 20042 min read 99.2K   869   59   5
A button that can be used together with a panel to make ToolBars, or just for everything else buttons are used for

Sample Image - NSButton.gif


I don't like the standard ToolBars included in .NET, and the buttons have problems showing some details in 24-bit color bitmaps.

I looked around for a button I could use for making a "ToolBar" by just using a Panel and some buttons, but I did not find any that looked and acted the way I would like.  That's why I started writing my own, and I think it came out pretty well, at least for my use.

One small note: I wrote this button fairly quickly and just forgot about everything while coding it. When I enter that state, I sometime forget to write comments, so there aren't a lot of comments in this code at the moment.  I'll try to add some useful comments at a later time...

Whats so special about this button...

  • It acts a bit like the toolbar buttons in VS .NET and Office 2003.
  • It's flat, only draws a border and background when the mouse is over the button, and it can show both bitmaps and text.
  • It can show the text either at the bottom or to the right of the bitmap, or just show the bitmap centered without any text.
  • It's also able to show a ToolTip, as I wrote it for use in ToolBars.

I found the class called ControlPaint in the .NET framework--this class can help with a lot of issues when writing controls.  I use the DrawImageDisabled() function to paint the bitmap on the button when it's disabled.  That way the bitmap is shown as we are used to seeing a "disabled button" bitmap in other buttons.

The different properties

  • ButtonForm
    • Rectangle: The button has the form a typical button--rectangular.
    • Ellipse: The button has an ellipse form, where the buttons region is actually set to the ellipse form so the mouse has to actually enter the ellipse to be able to click the button--it's not enough to click one of the "hidden corners" as it is with most rounded buttons.
  • TextAlign
    • Bottom: The text is showed centered on the button under the bitmap.
    • Right: The text is showed vertically centered to the right of the bitmap.
    • None: No text is showed and the bitmap is centered on the button.
  • HighLightColor: The color that fills the background of the button, when the mouse is over it.
  • OnlyShowBitmap: If this is set to true, no border, HighLightColor, or Text is ever painted, only the bitmap(s).
  • ToolTip: The ToolTip is displaye when the mouse hovers over the button.
  • NormalImage: The image that is shown when the button just sits "idle" and nothing is happening with it.
  • HottrackImage: The bitmap that is shown when the mouse enters the button.  If this bitmap is null, the NormalImage bitmap is shown instead.
  • PressedImage: The bitmap that is shown when the user "clicks" on the button.  If this bitmap is null, the NormalImage bitmap is shown instead.


2003-01-13 Version 1.0 released.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Written By
Software Developer (Senior)
Denmark Denmark
Huh! Wink | ;-)

Comments and Discussions

QuestionLicense Pin
OTmsz13-Dec-12 0:06
OTmsz13-Dec-12 0:06 
GeneralSmall modification Pin
Boris Russel16-Jan-04 3:17
Boris Russel16-Jan-04 3:17 
GeneralRe: Small modification Pin
Anders Molin16-Jan-04 3:23
professionalAnders Molin16-Jan-04 3:23 
GeneralEcellent work Pin
bigolslabomeat13-Jan-04 22:46
bigolslabomeat13-Jan-04 22:46 
GeneralRe: Ecellent work Pin
Anders Molin14-Jan-04 1:12
professionalAnders Molin14-Jan-04 1:12 

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.