如何更改禁用的CRichEditCtrl的背景颜色? [英] How to change background color of disabled CRichEditCtrl?

查看:214
本文介绍了如何更改禁用的CRichEditCtrl的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我已经创建了一个波纹管CRichEditCtrl对象,并尝试使用 SetBackgroundColor() 方法将红色作为背景,但是我希望它没有给出结果.

Hi Friends,
I have created a CRichEditCtrl object as bellow and i tried to apply red color as background using SetBackgroundColor() method but its not giving result as i hope.

m_oRichEditCtrl.Create(WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_DISABLED,CRect(0,0,150,150),this,IDC_RICHEDIT);
COLORREF oldColor = m_oRichEditCtrl.SetBackgroundColor(FALSE,COLORREF(RGB(255,0,0)));
m_oRichEditCtrl.SetWindowText("Hello");



我发现当我给出WS_DISABLED 样式时,它没有将背景色应用为红色.
禁用Richedit控件后,是否可以更改其背景颜色?

我应该使用 CDialog::OnCtlColor() 方法来更改RichEditCtrl的背景颜色吗?

谢谢大家.



I found that when i give WS_DISABLED style, its not applying background color as red.
Is there any way to change background color of richedit control when its disabled?

Should i go for CDialog::OnCtlColor() method to change background color of RichEditCtrl??

Thanks All.

推荐答案

我不确定自从动态创建以来,是否为此丰富的编辑控件调用了OnCtlColor().因此,最简单的方法是
1.创建一个从MFC CRichEditCtrl派生的名为CMyRichEditCtrl的类. 2.通过重写OnEnable()函数来处理此新类中的WM_ENABLE消息
3.在OnEnable()函数中检查其参数并相应地更改背景颜色(该参数表示禁用或启用)
4.将m_oRichEditCtrl的类型设置为CMyRichEditCtrl
5.在对话框类的OnInitDialog()中创建Rich编辑控件,如下所示
I am not sure whether OnCtlColor() gets invoked for this rich edit control since created dynamically. So one easiest way to do this is
1. Create a class called CMyRichEditCtrl derived from MFC CRichEditCtrl
2. Handle the WM_ENABLE message within this new class by overriding OnEnable() function
3. Inside the OnEnable() function check its parameter and change the background color accordingly(parameter indicates disable or enable)
4. Make the type of your m_oRichEditCtrl as CMyRichEditCtrl
5. Create the Rich edit control within the OnInitDialog() of your dialog class as below
m_oRichEditCtrl.Create( WS_CHILD|WS_VISIBLE|ES_MULTILINE,
                        CRect0,0,150,150),this,IDC_RICHEDIT );
m_oRichEditCtrl.SetWindowText("Hello");


6.不要忘记评论CRichEditCtrl :: OnEnable(bEnable);.在OnEnable()函数中


6. Do not forget to comment CRichEditCtrl::OnEnable(bEnable); inside the OnEnable() function

//CRichEditCtrl::OnEnable(bEnable);


如果需要任何澄清,我可以提供帮助


If any clarification needed I can help


这篇关于如何更改禁用的CRichEditCtrl的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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