翻译来源:https://www.codeproject.com/Articles/5242/XColorStatic-a-colorizing-static-control

XColor Static是一个简单的基于静态框的控件,它提供字体更改,文本和背景颜色以及图标显示。

介绍

XColor Static是一种通用控件,允许在对话框中显示漂亮的文本。该演示向您展示了可能的文本和图标显示类型:

XColorstatic API

以下是完整的方法列表:CXColorStatic

 
void SetBackgroundColor(COLORREF rgb, BOOL bRedraw = TRUE);
void SetTextColor(COLORREF rgb, BOOL bRedraw = TRUE);
void SetBold(BOOL bFlag, BOOL bRedraw = TRUE);
void SetFont(LPCTSTR lpszFaceName, int nPointSize, BOOL bRedraw = TRUE);
void SetFont(LOGFONT *pLogFont, BOOL bRedraw = TRUE);
void SetFont(CFont *pFont, BOOL bRedraw = TRUE);
void SetIcon(HICON hIcon, BOOL bRedraw = TRUE);
void SetMargins(int x, int y) { m_nXMargin = x; m_nYMargin = y; }

如何使用

要将XColor Static集成到应用程序中,首先需要将以下文件添加到您的项目中:

  • XColorstatic.cpp
  • XColor static.h
  • FontSize.cpp
  • FontSize.h

然后使用资源编辑器将静态控件添加到对话框中,并使用类向导将成员变量附加到该控件。请注意,添加静态控件时,您必须将其命名为除。IDC_STATIC

接下来,包含头文件XColor static .H在对话框的头文件。然后用。现在你准备开始使用XColor Static

用法

  1. BOOL CXColorStaticTestDlg::OnInitDialog()
  2. {
  3. CDialog::OnInitDialog();
  4. // Add "About..." menu item to system menu.
  5. // IDM_ABOUTBOX must be in the system command range.
  6. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  7. ASSERT(IDM_ABOUTBOX < 0xF000);
  8. CMenu* pSysMenu = GetSystemMenu(FALSE);
  9. if (pSysMenu != NULL)
  10. {
  11. CString strAboutMenu;
  12. strAboutMenu.LoadString(IDS_ABOUTBOX);
  13. if (!strAboutMenu.IsEmpty())
  14. {
  15. pSysMenu->AppendMenu(MF_SEPARATOR);
  16. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  17. }
  18. }
  19. // Set the icon for this dialog.  The framework does this automatically
  20. //  when the application's main window is not a dialog
  21. SetIcon(m_hIcon, TRUE);         // Set big icon
  22. SetIcon(m_hIcon, FALSE);        // Set small icon
  23. m_Banner.SetTextColor(RGB(0,0,255), FALSE);
  24. m_Banner.SetBackgroundColor(RGB(155,115,255), FALSE);
  25. m_Banner.SetBold(TRUE, FALSE);
  26. m_Banner.SetFont(_T("Comic Sans MS"), 20, FALSE);
  27. HICON hIcon = AfxGetApp()->LoadIcon(IDI_SHERLOCK);
  28. m_Icon.SetIcon(hIcon);
  29. m_Icon.SetBackgroundColor(RGB(201,201,255), FALSE);
  30. m_Text1.SetWindowText(
  31. _T("To Sherlock Holmes she is always THE woman.  I have seldom heard ")
  32. _T("him mention her under any other name.  In his eyes she eclipses ")
  33. _T("and predominates the whole of her sex.  It was not that he felt ")
  34. _T("any emotion akin to love for Irene Adler."));
  35. m_Text1.SetMargins(15, 0);
  36. m_Text1.SetFont((LPCTSTR)NULL, 10, FALSE);
  37. m_Text2.SetBold(TRUE, FALSE);
  38. m_Text2.SetFont(_T("Arial"), 14, FALSE);
  39. m_Text2.SetWindowText(_T("But wait...  There's MORE!!!"));
  40. m_Text2.SetMargins(15, 0);
  41. m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);
  42. m_Text3.SetWindowText(
  43. _T("One night -- it was on the twentieth of March, 1888 -- I was ")
  44. _T("returning from a journey to a patient (for I had now returned to ")
  45. _T("civil practice), when my way led me through Baker Street.  As I ")
  46. _T("passed the well-remembered door, which must always be associated ")
  47. _T("in my mind with my wooing, and with the dark incidents of the ")
  48. _T("Study in Scarlet, I was seized with a keen desire to see Holmes ")
  49. _T("again, and to know how he was employing his extraordinary powers."));
  50. m_Text3.SetMargins(15, 0);
  51. m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);
  52. m_Text4.SetMargins(15, 0);
  53. LOGFONT lf;
  54. CFont *pFont = m_Text4.GetFont();
  55. pFont->GetLogFont(&lf);
  56. lf.lfItalic = TRUE;
  57. _tcscpy(lf.lfFaceName, _T("Verdana"));
  58. m_Text4.SetFont(&lf, FALSE);
  59. return TRUE;  // return TRUE  unless you set the focus to a control
  60. }

该软件发布到公共领域。您可以随意使用任何您喜欢的方式。如果您修改它或扩展它,请考虑发布新的代码在这里供大家分享。该软件按“原样”提供,没有明示或默示的保证。对于此软件可能导致的任何损坏或业务损失,我不承担任何责任。

修订记录

版本1.0 - 2003年10月17日

  • 首次公开发布。
 

评论和讨论

全透明背景 wlburgess 20-Oct-05 6:54 

感谢Hans为优秀的静态框控制。

透明度是我在许多演示类型Dialog Apps中的一个目标。

以前的解决方案有效,但在某些情况下需要太多的背景知识。

这是一个简单的解决方案,让文本画在已经存在的背景上。

要打开“静态”控件的“透明度”,请使用“对话框编辑器”将“透明度”的“扩展样式”复选框设置为“true” - 将“关闭”默认为具有完整背景的常规“不透明”文本。

首先在OnPaint中,成员函数的顶部现在将如下所示:
void CXColorStatic :: OnPaint()

CPaintDC dc(this); //设备上下文绘制

dc.SaveDC();

dc.SetTextColor(m_rgbText); 
if(!(GetExStyle()&
WS_EX_TRANSPARENT)) { 
dc.SetBkColor(m_rgbBackground); 
dc.SetBkMode(TRANSPARENT); 

else 

dc.SetBkMode(TRANSPARENT); 

dc.SelectObject(m_pBrush);

CRect rect; 
GetClientRect(RECT);

...(其余与以前一样)

第二个设置EraseBackground :
BOOL CXColorStatic :: OnEraseBkgnd(CDC * pDC)

if(!(GetExStyle()&WS_EX_TRANSPARENT))

CRect cr; 
GetClientRect(CR); 
pDC-> FillRect(&cr,m_pBrush); 
}

return TRUE; //的CStatic :: OnEraseBkgnd(PDC); 
}

Wayne L. Burgess 

 

译者见解:

实现透明度以上方法在属性框设置 TRANSPARENT=TRUE,这就需要一个一个控件去修改;如果是动态创建,可以增加WS_EX_TRANSPARENT,在

void CXColorStatic::PreSubclassWindow() 
{
TRACE(_T("in CXColorStatic::PreSubclassWindow\n"));
  ModifyStyleEx(0, WS_EX_TRANSPARENT);
// get current font

已修改的源码案例:http://download.csdn.net/detail/greless/9898892

http://download.csdn.net/detail/greless/9897974

http://blog.csdn.net/greless/article/category/6970425

一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类(比较好看,一共19篇自绘文章)的更多相关文章

  1. MFC 可以设置背景色、字体、字体颜色、透明背景的 Static 静态文本控件

    MFC库里没有符合这个条件的控件,于是我自己写了一个,初步测试有效. 注:可以设置透明背景,但还不能做到透明度设置(如50%透明度) 如果设置了背景色,就不保留透明背景 默认背景色是透明的 [cpp] ...

  2. 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...

  3. 用c/c++混合编程方式为ios/android实现一个自绘日期选择控件(一)

    本文为原创,如有转载,请注明出处:http://www.cnblogs.com/jackybu 前言 章节: 1.需求描述以及c/c++实现日期和月历的基本操作 2.ios实现自绘日期选择控件 3.a ...

  4. Android一个炫酷的树状图组织架构图开源控件实现过程

    Android一个炫酷的树状图组织架构图开源控件 文章目录 [1 简介] [2 效果展示] [3 使用步骤] [4 实现基本布局流程] [5 实现自由放缩及拖动] [6 实现添加删除及节点动画] [7 ...

  5. 『Asp.Net 组件』第一个 Asp.Net 服务器组件:自己的文本框控件

    代码: using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DemoWebControl ...

  6. 给easyui datebox时间框控件扩展一个清空的实例

    给easyui datebox扩展一个清空的实例 步骤一:拓展插件 /** * 给时间框控件扩展一个清除的按钮 */ $.fn.datebox.defaults.cleanText = '清空'; ( ...

  7. MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应

    MFC小程序截图: 一.在MFC中简单使用WebBrowser的ActiveX插件的方法: 见博文:  http://blog.csdn.net/supermanking/article/detail ...

  8. putty字体大小颜色、全屏/退出全屏快捷键 保存session设置[转]

    字体大小设置 Window->Appearance->Font settings->Change按钮设置(我的设置为16)字体为(Consolas) 字体颜色设置 Window-&g ...

  9. Android-修改TabWidget字体大小颜色及对齐

    在Android中,我们可以定义TabWidget来分页.在上一篇文章中有说到使用TabWidget定义Tab分页布局,但大部分用户可能会觉得默认的字体有点小,但Tab选项卡默认又不能设定字体大小,如 ...

随机推荐

  1. jquery-6 jquery属性选择器

    jquery-6 jquery属性选择器 一.总结 一句话总结:jquery操作就是选择器加jquery对象的各种方法. 1.大量操作样式用什么方式? 大批量样式通过加类和减类完成 2.jquery中 ...

  2. 常用服务器ftp、ssh

    1. Linux常用服务器构建-ftp服务器 ftp服务器 FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议". 用于Int ...

  3. USACO--2.1The Castle

    思路:这个题目难在建图,開始的时候我想把每一个房间没有墙的面求出来,然后再和他邻近的房间加上一条边进行建图,后面发现要通过题目给定的条件求出房间那个面没有墙是十分困难的:后面參考了别人的思路,我们记录 ...

  4. 小强的HTML5移动开发之路(45)——汇率计算器【1】

    这两天看了<PhoneGap实战>上面有一个汇率计算器的例子,个人觉得比较好,就拿出来和大家分享一下,在接下来的几篇文章中我们来一起完成这个PhoneGap + Jquery mobile ...

  5. 【t075】郁闷的记者

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 你是一个体育报社的记者,你接受到一个艰难的任务:有N支足球队参加足球比赛,现在给你一些比赛的结果,需要 ...

  6. 【BZOJ 1037】[ZJOI2008]生日聚会Party

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1037 [题意] [题解] /* 设f[i][j][k][l] 表示前i个人中,有j个男 ...

  7. zookeeper 半数可用/选举机制

    1.半数可用机制,半数可用指的是zk集群中一半以上的机器正常时集群才能正常工作 已经启动了hadoop002(follower),hadoop003(leader) 下面停止hadoop002 在ha ...

  8. 在intellij idea 中怎么不用git 解除关联

    展开全部 file ->settings->version control 选中这一栏,右边有个 点红色减号,就解除了,然后去项目目录下删除.git这个文件夹,你可以不删除,为了以后继续关 ...

  9. spring-boot-sample-web-jsp

    Pom文件需要配置的: <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl&l ...

  10. Using default security password

    不展示Using default security password的解决办法: import org.springframework.context.annotation.Bean; import ...