Introduction
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.
- Design the dialog box in the normal way.
- Create an
OnInitDialog
function using the class wizard.
- Add Label.cpp and Label.h to your project.
#Include <label.cpp>
in your dialog .cpp file.
- Delete the project '.clw' file and regenerate by opening the project and
pressing Ctrl+W
- Any static controls that need enhancing, give each control a unique ID
within the dialog editor.
- Assign each member controls (
CLabel
) to each ID using the
class wizard.
- In
OnInitDialog
uses the CLabel
API 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_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_lblGradient.SetBkColor(RGB(255,255,255),RGB(0,0,255), CLabel::Gradient);
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);
History
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