wxWidgets第六课 EVT_ERASE_BACKGROUND背景擦除事件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wxWidgets第六课 EVT_ERASE_BACKGROUND背景擦除事件相关的知识,希望对你有一定的参考价值。
说明
默认情况下,OnEraseBackground函数负责背景颜色的渲染,OnPaint函数负责前景颜色的渲染。系统提供的默认的背景颜色函数将背景渲染成白色,会引起控件区域闪烁。可以通过重写背景擦除事件处理函数,减少闪烁
例子
void OnEraseBackground(wxEraseEvent& event);
EVT_ERASE_BACKGROUND(CDownLinkPlaybackSliderCtrl::OnEraseBackground)
void CDownLinkPlaybackSliderCtrl::OnEraseBackground(wxEraseEvent& event)
{
wxClientDC dc(this);
wxSize size = this->GetSize();
int width = size.GetWidth();
int height = size.GetHeight();
int middleHeight = height/2;
dc.SetPen(wxPen(*wxBLACK, 2));
// dc.DrawLine(0, middleHeight-1, width, middleHeight-1);
// dc.DrawLine(0, middleHeight+1, width, middleHeight+1);
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRectangle(2, middleHeight-2, width-4, 4);
int topDialHeight = middleHeight-2;
int buttonDialHeight = middleHeight+2;
int averageGap = (width-4)/25;
int count = 0;
for (int i=2; i<width-4; i=i+averageGap)
{
dc.DrawLine(i, topDialHeight, i, topDialHeight-2);
dc.DrawLine(i, buttonDialHeight, i, buttonDialHeight+2);
if (count%4==0)
{
char szText[4] ={0};
sprintf(szText, "%d", count);
wxRect rect(i-3, topDialHeight-2-3, 3, 3);
dc.DrawLabel(szText, rect, 1);
}
count++;
}
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(m_sliderLen-3, middleHeight - 2, 4, 6);
}
以上是关于wxWidgets第六课 EVT_ERASE_BACKGROUND背景擦除事件的主要内容,如果未能解决你的问题,请参考以下文章