Extended Use of CStatic Class

CLabel image Download Source Code and Example


Every wanted a static control that behaved like a Visual Basic(yuk!) label control? Well this could be just the thing you might be looking for. The first cut version of this MFC extension class will allow you to change the text, font attributes (weight, underline, size, name), text color, background color and border style.

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

  1. Design the dialog box in the normal why.
  2. Create a OnInitDialog function using the class wizard.
  3. Add Label.cpp and Label.h to your project.
  4. #Include <label.h> in your dialog .cpp file.
  5. Any static controls that need enhancing, give each control a unique ID.
  6. Assign a member control (CLabel) to each ID using the class wizard.
  7. In OnInitDialog change a static controls appearing the functions provided. (See Label.h)

API of CLabel

CLabel& SetBkColor(COLORREF crBkgnd) Set the background colour of the control
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.

Example of CLabel

    m_fname.SetFontName("System");
    m_fsize.SetFontSize(14);
    m_uline.SetFontUnderline(TRUE);
    m_tcolor.SetTextColor(RGB(255,0,0));
    m_bcolor.SetBkColor(RGB(0,255,255));
    m_italics.SetFontItalic(TRUE);
    m_bold.SetFontBold(TRUE);
    m_border.SetBorder(TRUE);
    m_sunken.SetSunken(TRUE);

    m_monty.SetFontName("Arial");
    m_monty.SetFontSize(12);
    m_monty.SetTextColor(RGB(255,255,0));
    m_monty.SetFontUnderline(TRUE);
    m_monty.SetBkColor(RGB(0,0,0));
    m_monty.SetFontItalic(TRUE);
    m_monty.SetFontBold(TRUE);
    m_monty.SetBorder(TRUE);
    m_monty.SetSunken(TRUE);

Last Updated: May 30 1998



Comments

  • ghd australia ubpblb

    Posted by Mandygxn on 02/08/2013 03:09am

    8hVvr ugg mUoa ¥È¥ê©`¥Ð©`¥Á ¥Ð¥Ã¥° lRww nike shox dame 5qHlr toms outlet 1lHxa hollister sale 1lLux 9fMfb portefeuille longchamp 1gGmp cheap louis vuitton 7rGzr michael kors outlet 0eVzz christian louboutin norge 5qBmf kaepernick jersey 9rKwd 5kHib ghd 4yLpz ghd france 5gWfv ugg boots

    Reply
  • thanks

    Posted by vlongsoft on 09/06/2005 11:28pm

    Thank you very much!

    Reply
  • Static control in dlg

    Posted by Legacy on 01/21/2004 12:00am

    Originally posted by: Ranjith George


    Hi all,
    Can I delete the static control and create it during run time ?? Please tell me the function for doing this operation ???

    Reply
  • pCLabel->Create RedrawWindow()

    Posted by Legacy on 11/18/2003 12:00am

    Originally posted by: francovics

    Just a minor comment, when creating CLabel objects in your initdialog() function like

    CLabel* pLabel = new CLabel;

    you have to blank out the RedrawWindow function in the Label.ccp code...

    Reply
  • Its nice

    Posted by Legacy on 09/16/2003 12:00am

    Originally posted by: Arbind Yadav

    hi

    Really ,it is good attempt.

    Arbind Yadav

    Reply
  • thanks

    Posted by Legacy on 05/15/2003 12:00am

    Originally posted by: mehmet Erdem

    I am actually a unix programmer, very new in mfc thus...This was what i was looking for days, thank you very much.

    Reply
  • thanks

    Posted by Legacy on 04/01/2003 12:00am

    Originally posted by: jkusa

    thanks for the nice help

    Reply
  • cannot assign CLabel to static control thru the class wizard

    Posted by Legacy on 03/26/2003 12:00am

    Originally posted by: ahmoy law

    i hav copied the CLabel.cpp and CLabel.h into my own project. but then i cannot assign CLabel to static control using class wizard in the member variables section. strangely, in the downloaded project, the option given to me is CLabel and CStatic.

    Thanks in advance,
    ahmoy law

    Reply
  • Static

    Posted by Legacy on 01/03/2003 12:00am

    Originally posted by: Wei

    Thanks. Test.

    Reply
  • open image files(bmp, jpg, tga) on static control

    Posted by Legacy on 11/28/2002 12:00am

    Originally posted by: vibhavari

    how to open image files(bmp, jpg, tga) on static control?
    
    and also these files fit in static size without scroll bar.according to the size of static control image become small or big.
    please anybody have solution please send me on patelvibha@rediffmail.com.
    eagerly waiting for your reply.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds