MFC: Changing the colour of CEdit(MFC:更改 CEdit 的颜色)
问题描述
伙计们,谁能简要介绍一下如何在运行时更改 CEdit 控件的背景颜色?如果字段长度为零,我希望能够将背景更改为红色,否则为正常白色.
Guys, can someone give me a brief run through of how to change the background colour of a CEdit control at runtime? I want to be able to change the background to red if the field is zero length and the normal white otherwise.
推荐答案
你不能用一个普通的 CEdit 来完成,你需要覆盖一些位.
You cannot do it with a plain CEdit, you need to override a few bits.
实现您自己的 ON_WM_CTLCOLOR_REFLECT 处理程序,然后在处理程序中返回您的彩色 CBrush:
Implement your own ON_WM_CTLCOLOR_REFLECT handler, then return your coloured CBrush in the handler:
(粗略地说,你需要把常用的资源管理放在那里,记住在析构函数中删除你的画笔)
(roughly, you'll need to put the usual resource management in there, rememebr to delete your brush in the destructor)
class CColorEdit : public CEdit
{
....
CBrush m_brBkgnd;
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor)
{
m_brBkgnd.DeleteObject();
m_brBkgnd.CreateSolidBrush(nCtlColor);
}
}
这篇关于MFC:更改 CEdit 的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MFC:更改 CEdit 的颜色
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07