Click here to Skip to main content
Licence 
First Posted 12 Jan 2004
Views 82,494
Bookmarked 60 times

NSButton

By | 12 Jan 2004 | Article
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

Introduction

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.

History

2003-01-13 Version 1.0 released.

License

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

About the Author

Anders Molin

Software Developer (Senior)

Denmark Denmark

Member

Huh! Wink | ;-)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSmall modification PinmemberBoris Russel2:17 16 Jan '04  
GeneralRe: Small modification PinmemberAnders Molin2:23 16 Jan '04  
GeneralEcellent work Pinmemberbigolslabomeat21:46 13 Jan '04  
GeneralRe: Ecellent work PinmemberAnders Molin0:12 14 Jan '04  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 13 Jan 2004
Article Copyright 2004 by Anders Molin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid