我有一个包含许多控件的对话框。例如:编辑控件。 现在我正在开发这些具有彩色边框的编辑控件。 但是每次用户在编辑控件中输入输入时控件都会重新绘制,因此边框会闪烁。 现在我想在具有此控件的对话框上绘制边框。在mfc中可以吗?
最佳答案
您可以通过自定义您的控件类并在非客户区绘图来实现这一点。 我已经在我的项目中实现了这个,没有闪烁问题。
思路是这样的:
/////////////////////////////////////////////////////////////////////////////
///
/// /This method is overriden, to modify the style of editcrtl
///
/////////////////////////////////////////////////////////////////////////////
void CEdit1::PreSubclassWindow()
{
ModifyStyleEx(0, WS_EX_STATICEDGE, 0); //to make sure your border is static edge
}
在非客户区你只画红色矩形:
/////////////////////////////////////////////////////////////////////////////
///
/// /This handler is used to paint the non- client area
///
/// /return none
///
/////////////////////////////////////////////////////////////////////////////
void CEdit1::OnNcPaint()
{
CDC* pDC = GetWindowDC();
//work out the coordinates of the window rectangle,
CRect rect;
GetWindowRect( &rect);
rect.OffsetRect( -rect.left, -rect.top);
//Draw a single line around the outside
CBrush brush(RGB(255,0,0));
pDC->FrameRect(&rect, &brush);
ReleaseDC( pDC);
}
关于c++ - 在mfc中绘制父对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44229357/