65.9K
CodeProject 正在变化。 阅读更多。
Home

PocketPC 的 CFontStatic

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.87/5 (8投票s)

2004年10月29日

CPOL
viewsIcon

36190

downloadIcon

234

一个用于设置静态文本各种属性的类,例如字体、颜色或对齐方式。

Sample Image - CFontStatic.gif

引言

这是 Patrik Svensson 的 CFontStatic 类 的 PocketPC 移植版本,并进行了一些修改。该类允许轻松设置静态文本的各种属性,例如颜色、字体或对齐方式。

使用代码

CFontStatic 类包含以下方法

// set background color
void SetBackground(DWORD dwBgColor);
void SetBackground(int red, int green, int blue);

// set text color
void SetForeground(DWORD dwForeColor);
void SetForeground(int red, int green, int blue);

// set font attributes
void SetFontStatic(CString szFont, int nSize, 
                   DWORD dwColor, FontStyle dwStyle);
void SetFontStatic(CString szFont, int nSize);
void SetFontStatic(CString szFont);
void SetFontSize(int nSize);
void SetFontStyle(FontStyle dwStyle);

// set text alignment
void SetAlignment(AlignStyle style);

为了使用该类,您需要在代码中声明类的实例

CFontStatic myLabel;

或者将对话框/视图类的 CFontStatic 成员与资源在 DoDataExchange() 中关联。

DDX_Control(pDX, IDC_LBL_TOP, m_myLabel);

这是一个设置各种属性的示例。您可以一次性设置所有属性,也可以仅设置您需要的属性

// set all attributes in one hit
m_lblTop.SetFontStatic(_T("Courier New"), 
         16, RGB(255, 255, 255), CFontStatic::FS_BOLD);

// alignment is set separately
m_lblMid.SetAlignment(CFontStatic::FS_CENTER);
m_lblMid.SetFontStatic(_T("Tahoma"), 18, GetSysColor(COLOR_STATICTEXT), 
                                         CFontStatic::FS_UNDERLINED);

// set attributes one by one
m_lblBot.SetBackground(255, 255, 255);
m_lblBot.SetForeground(0, 0, 128);
m_lblBot.SetFontSize(20);
m_lblBot.SetFontStatic(_T("Frutiger Linotype"));
m_lblBot.SetFontStyle(CFontStatic::FS_ITALIC);
// note that multiple calls of SetFontStyle()
// are needed to set more than one attribute
m_lblBot.SetFontStyle(CFontStatic::FS_UNDERLINED); 
m_lblBot.SetAlignment(CFontStatic::FS_RIGHT);

历史

  • 2004/10/29 - 首次提交。
© . All rights reserved.