MFC:更改CEdit的颜色 [英] MFC: Changing the colour of CEdit

查看:254
本文介绍了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.

推荐答案

如果字段长度为零,那么我想将背景更改为红色。

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:

(大致来说,你需要把常用的资源管理放在里面,rememebr在析构函数中删除你的画笔)

(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的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆