一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类(比较好看,一共19篇自绘文章)
翻译来源:https://www.codeproject.com/Articles/5242/XColorStatic-a-colorizing-static-control
介绍
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。
用法
- BOOL CXColorStaticTestDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- m_Banner.SetTextColor(RGB(0,0,255), FALSE);
- m_Banner.SetBackgroundColor(RGB(155,115,255), FALSE);
- m_Banner.SetBold(TRUE, FALSE);
- m_Banner.SetFont(_T("Comic Sans MS"), 20, FALSE);
- HICON hIcon = AfxGetApp()->LoadIcon(IDI_SHERLOCK);
- m_Icon.SetIcon(hIcon);
- m_Icon.SetBackgroundColor(RGB(201,201,255), FALSE);
- m_Text1.SetWindowText(
- _T("To Sherlock Holmes she is always THE woman. I have seldom heard ")
- _T("him mention her under any other name. In his eyes she eclipses ")
- _T("and predominates the whole of her sex. It was not that he felt ")
- _T("any emotion akin to love for Irene Adler."));
- m_Text1.SetMargins(15, 0);
- m_Text1.SetFont((LPCTSTR)NULL, 10, FALSE);
- m_Text2.SetBold(TRUE, FALSE);
- m_Text2.SetFont(_T("Arial"), 14, FALSE);
- m_Text2.SetWindowText(_T("But wait... There's MORE!!!"));
- m_Text2.SetMargins(15, 0);
- m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);
- m_Text3.SetWindowText(
- _T("One night -- it was on the twentieth of March, 1888 -- I was ")
- _T("returning from a journey to a patient (for I had now returned to ")
- _T("civil practice), when my way led me through Baker Street. As I ")
- _T("passed the well-remembered door, which must always be associated ")
- _T("in my mind with my wooing, and with the dark incidents of the ")
- _T("Study in Scarlet, I was seized with a keen desire to see Holmes ")
- _T("again, and to know how he was employing his extraordinary powers."));
- m_Text3.SetMargins(15, 0);
- m_Text3.SetFont((LPCTSTR)NULL, 10, FALSE);
- m_Text4.SetMargins(15, 0);
- LOGFONT lf;
- CFont *pFont = m_Text4.GetFont();
- pFont->GetLogFont(&lf);
- lf.lfItalic = TRUE;
- _tcscpy(lf.lfFaceName, _T("Verdana"));
- m_Text4.SetFont(&lf, FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- }
该软件发布到公共领域。您可以随意使用任何您喜欢的方式。如果您修改它或扩展它,请考虑发布新的代码在这里供大家分享。该软件按“原样”提供,没有明示或默示的保证。对于此软件可能导致的任何损坏或业务损失,我不承担任何责任。
修订记录
版本1.0 - 2003年10月17日
- 首次公开发布。
评论和讨论
|
|||||
|
|||||
译者见解:
实现透明度以上方法在属性框设置 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篇自绘文章)的更多相关文章
- MFC 可以设置背景色、字体、字体颜色、透明背景的 Static 静态文本控件
MFC库里没有符合这个条件的控件,于是我自己写了一个,初步测试有效. 注:可以设置透明背景,但还不能做到透明度设置(如50%透明度) 如果设置了背景色,就不保留透明背景 默认背景色是透明的 [cpp] ...
- 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.si ...
- 用c/c++混合编程方式为ios/android实现一个自绘日期选择控件(一)
本文为原创,如有转载,请注明出处:http://www.cnblogs.com/jackybu 前言 章节: 1.需求描述以及c/c++实现日期和月历的基本操作 2.ios实现自绘日期选择控件 3.a ...
- Android一个炫酷的树状图组织架构图开源控件实现过程
Android一个炫酷的树状图组织架构图开源控件 文章目录 [1 简介] [2 效果展示] [3 使用步骤] [4 实现基本布局流程] [5 实现自由放缩及拖动] [6 实现添加删除及节点动画] [7 ...
- 『Asp.Net 组件』第一个 Asp.Net 服务器组件:自己的文本框控件
代码: using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace DemoWebControl ...
- 给easyui datebox时间框控件扩展一个清空的实例
给easyui datebox扩展一个清空的实例 步骤一:拓展插件 /** * 给时间框控件扩展一个清除的按钮 */ $.fn.datebox.defaults.cleanText = '清空'; ( ...
- MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应
MFC小程序截图: 一.在MFC中简单使用WebBrowser的ActiveX插件的方法: 见博文: http://blog.csdn.net/supermanking/article/detail ...
- putty字体大小颜色、全屏/退出全屏快捷键 保存session设置[转]
字体大小设置 Window->Appearance->Font settings->Change按钮设置(我的设置为16)字体为(Consolas) 字体颜色设置 Window-&g ...
- Android-修改TabWidget字体大小颜色及对齐
在Android中,我们可以定义TabWidget来分页.在上一篇文章中有说到使用TabWidget定义Tab分页布局,但大部分用户可能会觉得默认的字体有点小,但Tab选项卡默认又不能设定字体大小,如 ...
随机推荐
- 【codeforces 760A】Petr and a calendar
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- C语言递归实现二叉树的先序、中序、后序遍历
#include <stdio.h> #include <stdlib.h> //*****二叉树的二叉链表存储表示*****// typedef struct BiNode ...
- asp.net core2.1 部署centos7/linux系统 -- 安装部署(一)
原文:asp.net core2.1 部署centos7/linux系统 -- 安装部署(一) 1.安装dotnet sdk(添加产品秘钥与yum源) 添加yum源:sudo rpm -Uvh htt ...
- VC++中用API调用对话框资源
关键技术: 对于资源的载入须要几个API函数,以下分别介绍这几个API函数. a) FindResource 用来在一个指定的模块中定位所指的资源,语法例如以下: HRSRC FindResource ...
- js获取input file路径改变图像地址
版权声明:好歹是我写的或者总结的或者抄的,总待给我个名份吧~ https://blog.csdn.net/sangjinchao/article/details/52250318 html代码 < ...
- 【codeforces 779A】Pupils Redistribution
[题目链接]:http://codeforces.com/contest/779/problem/A [题意] 让你把两个组的5个人的数目都变成一样的. 支持交换操作; 问你最少需要交换几次. [题解 ...
- springboot 使用传统方式部署
spring boot默认创建出来的应用程序是内嵌web容器的,直接运行jar文件就可以的,但通常我们也需要将程序部署到tomcat中,这需要做如下改进: 1.pom.xml修改 打包方式需要修改成w ...
- Codeforces 106D Treasure Island 预处理前缀+暴力(水
主题链接:点击打开链接 意甲冠军: 特定n*m矩阵 # 是墙 . 和字母是平地 最多有26个字母(不反复出现) 以下k个指令. 每一个指令代表移动的方向和步数. 若以某个字母为起点,依次运行全部的指令 ...
- sublime Package Control 设备
sublime 插件的官方网站 https://sublime.wbond.net/ 点击Installation watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...
- 编程算法 - 背包问题(三种动态规划) 代码(C)
背包问题(三种动态规划) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目參考: http://blog.csdn.net/caroline_wen ...




