我有一个mfc应用程序。我在对话框上有一些richedit控件。我想在控件周围显示一个黄色的填充框。这样做的方法是什么?
我尝试在现有的richedit ctrl周围创建一个更丰富的编辑ctrl,并在其变量上使用SetBackgroundColor,但它为整个区域着色,其他richedit ctrls变得不可见。另外,我想在运行时更改周围的颜色。请帮我。我坚持这个。
可能有更好的方法来实现这一点,但是,以下应该可行。如果从CRichEditCtrl派生自己的类,则可以利用WM_NCPAINT消息来渲染边框。就像是…
void RichEdit::OnNcPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetWindowRect(&rect);
ScreenToClient(rect);
CPen pen;
pen.CreatePen(PS_SOLID, 10, RGB(255, 255, 0));
dc.SelectObject(pen);
dc.Rectangle(&rect);
CHARFORMAT cf = { 0 };
int txtLen = GetTextLength();
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_ITALIC;
SetSel(txtLen, -1); ReplaceSel("Some text");
// Apply formating to the just inserted text.
SetSel(txtLen, GetTextLength());
SetSelectionCharFormat(cf);
SetFocus();
// Do not call CRichEditCtrl::OnNcPaint() for painting messages
}
将边框渲染为黄色,并写入相应的文本。这是它的样子。