Click here to Skip to main content
Licence CPOL
First Posted 1 Mar 2002
Views 201,669
Bookmarked 54 times

CButton with icon

By | 12 Aug 2002 | Article
A small class to create a button with an icon on it

Sample Image - iconbutton.jpg

Introduction

The idea was to have a small piece of code which makes it easy to create a button with an icon on it. I saw a lot of great code, but it was not exactly what I want. So I decided to create my own CIconButton-class. This class makes it easy to set an icon on a button.

  1. Simply add a button to your dialog.
  2. Set the button style "ownerdraw", otherwise the code doesn't work.
  3. Then generate a member variable with the class-wizard.
  4. Change the class name from CButton to CIconButton (make sure you have include the "iconbutton.h" file and add the "iconbutton.cpp" file to your project)
  5. Create an icon in the resource manager.
  6. Set the icon to the button, set the font, the font size, etc

Last version

It´s possible to give the button a tool tip text. You can do this by calling the function SetTipText ( "tooltip-text" );

For more details look in the demo-project

Methods

void SetIconID ( const UINT nID )	
void SetTextColor ( const COLORREF color )	
void SetItalic ( bool bVal = true )
void SetUnderline ( bool bVal = true )	
void SetStrikeOut ( bool bVal = true )	
void SetFaceName ( const CString &sVal )
void SetWeight ( const int nVal )	
void SetHeight ( const int nVal)
void SetWidth ( const int nVal)	
void SetIconSize ( const int x, const int y )	
void SetIconRight ( bool bVal = true ) 
void SetTipText ( const CString &sTxt )  new

void Disable ( void );
void Enable ( void );

Note

I think this is the last enhancement, otherwise the "small piece of code" is going to get a big hunk ;-))

License

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

About the Author

Alexander Kloep

Software Developer
www.auteq.com
Germany Germany

Member

Working as software engineer since 2001 at www.auteq.com.
 
In my spare time i love playing with my two kids.

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
QuestionCompile with VS2010 [modified] Pinmembermerano10:15 24 Oct '11  
AnswerRe: Compile with VS2010 PinmemberAlexander Kloep19:56 24 Oct '11  
GeneralThanks PinmemberMember 10854029:34 18 Sep '10  
QuestionCan I use this code in commercial program Pinmemberhp15616:57 19 Sep '09  
AnswerRe: Can I use this code in commercial program [modified] PinmemberAlexander Kloep4:42 20 Sep '09  
GeneralThanks Pinmembernobihai4:25 26 Oct '08  
GeneralRe: Thanks PinmemberAlexander Kloep21:23 26 Oct '08  
GeneralChanging ToolTips PinmemberRedFraggle12:03 10 Jun '06  
GeneralRe: Changing ToolTips PinmemberAlexander Kloep20:44 11 Jun '06  
GeneralNice one PinmemberJaiju jacob0:14 9 Sep '05  
Questionhow to make colorful button such as red ,blue not gray Pinmembervividtang12:59 3 Apr '04  
AnswerRe: how to make colorful button such as red ,blue not gray Pinmembermerano10:39 24 Oct '11  
GeneralQ Pinmemberdeven chin1:43 15 Jan '04  
GeneralNice, but click speed is poor PinmemberC++ Hacker22:55 16 Nov '03  
GeneralSize of class PinmemberLapompe15:00 25 Jun '03  
QuestionHasn't this been done before? PinmemberEmcee Lam14:33 20 Dec '02  
AnswerRe: Hasn't this been done before? PineditorNishant S15:11 20 Dec '02  
GeneralRe: Hasn't this been done before? PinmemberEmcee Lam16:35 20 Dec '02  
GeneralRe: Hasn't this been done before? PinmemberRubyist21:51 8 Aug '07  
GeneralRe: Hasn't this been done before? PinmemberEmcee Lam16:36 13 Aug '07  
Generalgood Pinmemberyary1:48 19 Dec '02  
GeneralNice butt i got a problem PinmemberDosK23:18 19 Nov '02  
GeneralRe: Nice butt i got a problem PinmemberDosK23:41 19 Nov '02  
GeneralNice Class PinsussAnonymous9:47 9 Oct '02  
GeneralCONTROL on text and icon PinmemberAnonymous2:42 25 Jun '02  

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 Aug 2002
Article Copyright 2002 by Alexander Kloep
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid