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);

}


     本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1954794,如需转载请自行联系原作者





上一篇:Juniper netscreen防火墙TFTP升级过程


下一篇:centos7使用kubeadm配置高可用k8s集群