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

Extended Use of CStatic Class - CLabel 1.6

, 2 Aug 2002
Rate this:
Please Sign up or sign in to vote.
A fully stocked owner drawn CStatic class


Ever wanted a static control that behaved like a Visual Basic label control? Well this could be just the thing you might be looking for. This version adds all the functionality of the label control, plus many other features. The control uses double buffering which gives fast painting. The real work in done in the OnPaint function.

I've called the class CLabel and its simple to use in dialog boxes, just follow this simple instructions.

  1. Design the dialog box in the normal way.
  2. Create an OnInitDialog function using the class wizard.
  3. Add Label.cpp and Label.h to your project.
  4. #Include <label.cpp> in your dialog .cpp file.
  5. Delete the project '.clw' file and regenerate by opening the project and pressing Ctrl+W
  6. Any static controls that need enhancing, give each control a unique ID within the dialog editor.
  7. Assign each member controls (CLabel) to each ID using the class wizard.
  8. In OnInitDialog uses the CLabelAPI to change the appearance of the control.

API of CLabel

 CLabel& SetBkColor(COLORREF crBkgnd, 

          COLORREF crBkgndHigh = 0, 

          BackFillMode mode = Normal);

Set the background colour of the control and allows an optional gradient fill.
CLabel& SetText(const CString& strText) Sets the text of the controls
CLabel& SetTextColor(COLORREF crText) Sets the text colour of the control
CLabel& SetFontBold(BOOL bBold) Toggles the state of the bold attribute of the text in the control
CLabel& SetFontName(const CString& strFont) The the fonts face name in the control
CLabel& SetFontUnderline(BOOL bSet) Toggles the state of the underline font attribute of the control
CLabel& SetFontItalic(BOOL bSet) Toggles the state of the italic font attribute of the control
CLabel& SetFontSize(int nSize) Sets the fonts size in points.
CLabel& SetSunken(BOOL bSet) Toggles the state of the sunken attribue of the control
CLabel& SetBorder(BOOL bSet) Toggles the state of the borders attribute
CLabel& FlashText(BOOL bSet) Toggles the state of the text flashing attribute
CLabel& FlashBackground(BOOL bSet) Toggles the state of the text flashing attribute
CLabel& SetLink(BOOL bLink) Toggles the state of the link attribute (allows label to become internet link)
CLabel& SetLinkCursor(HCURSOR hCursor) Sets the cursor for the link.
CLabel& SetTransparency(BOOL bTransparency) Sets the transparency for the background.
CLabel& SetFont3D(BOOL bSet,Type3D type) Sets 3D fonts
CLabel& SetRotationAngle(UINT nAngle,BOOL bRotation) Sets rotation angle for font
CLabel& SetText3DHiliteColor(COLORREF cr3DHiliteColor) Sets the hi-light colour for the text
CLabel& SetMailLink(BOOL bEnable, BOOL bNotifyParent) Sets the hi-light colour for the text

Example of use

 m_lblGradient.SetBkColor(RGB(255,255,255),RGB(0,0,255), CLabel::Gradient);



CLabel Version 1.6

  • Jeroen Roosendaal - SetFont suggestion
  • Laurent - Spotting SelectObject bugs
  • Bernie - Fix PreCreateWindow bug
  • Jignesh I. Patel - Added expanded tabs feature
  • Jim Farmelant - Fix SetText crash


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

Software Developer (Senior) Software Kinetics
United Kingdom United Kingdom

Software Kinetics
are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.

We specialise in:

  • User Interface Design
  • Desktop Development
  • Windows Phone Development
  • Windows Presentation Framework
  • Windows Forms
  • Windows Communication Framework
  • Windows Services
  • Network Applications
  • Database Applications
  • Web Development
  • Web Services
  • Silverlight

Visit Software Kinetics
Follow on   Twitter

Comments and Discussions

QuestionHow to Auto Size text in CLabel [modified] Pinmembermasteryoda2127-Oct-11 11:33 
GeneralFlick Problem On Redraw - Solution [modified] Pinmembertonim9-Jun-10 12:48 
GeneralRe: Flick Problem On Redraw - Solution PingroupNorm .net9-Jun-10 22:21 
GeneralQuestion Pinmemberguyuewuhua31-Aug-09 17:29 
Generallicense restrictions for CLabel class PinmemberclintM22-Apr-09 8:24 
GeneralRe: license restrictions for CLabel class PinmemberNorm .net22-Apr-09 21:22 
GeneralRe: license restrictions for CLabel class PinmemberclintM23-Apr-09 3:32 
GeneralRe: license restrictions for CLabel class PinmemberAlan Hayslep29-Aug-13 1:45 
GeneralChanging font size [modified] Pinmembersabapathy_8021-Jan-09 4:59 
GeneralFlashing problems ( transparent label over bitmap ) Pinmemberalexuh13-Aug-08 5:21 
QuestionMaybe it's better that set byCharSet=DEFAULT_CHARSET in SetFontName? Pinmembersodar22-May-08 18:57 
Generaltext right aligned PinmemberJ.Charpentier26-Jun-07 8:05 
QuestionRotate Bitmaps? Pinmemberfrqftgbdafr29-May-07 11:47 
QuestionHelp on subclassing CLabel for suporting background image Pinmemberovidiu_pos16-May-07 22:03 
QuestionLicense? Pinmembertoschlog16-May-07 15:17 
AnswerRe: License? Pinmembernorm .net16-May-07 21:57 
QuestionEnable / Disable ? PinmemberChrisRibe19-Mar-07 7:03 
GeneralGot Slow Somewhere PinmemberPhil C27-Dec-05 16:26 
GeneralSemi-transparent, colored CLabel PinmemberDavid Fleming3-Sep-05 0:10 
GeneralSetWindowPos Pinmemberchris.lee@alcormicro.com29-Mar-05 21:26 
GeneralRe: SetWindowPos PinmemberOsborn27-Apr-06 6:21 
QuestionFlickerring? Pinmemberlily0lin5-May-04 10:22 
AnswerRe: Flickerring? PinmemberEastSeaBoy19-Sep-04 20:49 
GeneralRe: Flickerring? PinmemberEvanTao9-Dec-04 2:47 
GeneralRe: Flickerring? Pinmemberfeisi14-Jul-08 17:16 
GeneralWhite flash with transperent label Pinmemberlily0lin4-May-04 9:00 
GeneralMy only problem with this class is... PinmemberRavi Bhavnani28-Mar-04 9:44 
GeneralProblems Setting Window State Pinmemberyofnik8-Mar-04 11:10 
GeneralUNICODE PinmemberExtraLean20-Feb-04 10:21 
GeneralTransparency bug PinmemberEPulse15-Nov-03 20:22 
GeneralRe: Transparency bug Pinmemberalexuh21-Feb-08 7:14 
GeneralError loading IDC_HAND cursor PinmemberMarcus Carey24-Jul-03 20:46 
Generaladd #define IDC_HAND MAKEINTRESOURCE(32649) Pinmemberuranium991-Aug-03 3:43 
Generalfont size isn't changing Pinmemberconnorwr29-May-03 19:02 
GeneralRe: font size isn't changing Pinmemberconnorwr29-May-03 19:33 
GeneralMemory Leak PinmemberjimNLX28-Apr-03 8:31 
GeneralRe: Memory Leak PinmemberSledgeHammer28-Apr-03 9:53 
GeneralRe: Memory Leak PinmemberjimNLX28-Apr-03 10:46 
GeneralText Wrapping Pinmemberzipo1316-Feb-03 7:14 
GeneralRe: Text Wrapping PinmemberChen-Cha Hsu30-Sep-03 16:39 
GeneralMemory Leak PinsussAnonymous4-Feb-03 10:47 
GeneralRe: Memory Leak PinsussAnonymous4-Feb-03 11:14 
GeneralRe: Memory Leak PinmemberNorm Almond5-Feb-03 7:19 
GeneralRe: Memory Leak Pinmemberlily0lin19-Dec-03 17:03 
GeneralRe: Memory Leak Pinmember_corey_17-Nov-03 22:16 
GeneralRe: Memory Leak PinmemberNorm Almond3-Feb-04 1:30 
GeneralRe: Memory Leak PinmemberNorm Almond3-Feb-04 2:59 
GeneralThe underst line at the gradient fill locks bad PinmemberNitromouse18-Dec-02 6:59 
GeneralRe: The underst line at the gradient fill locks bad PinmemberNitromouse18-Dec-02 7:02 
GeneralPlease insert a tooltip function PinmemberNitromouse18-Dec-02 6:33 

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 | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 3 Aug 2002
Article Copyright 2000 by NormDroid
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid