码迷,mamicode.com
首页 > 其他好文 > 详细

wxWidgets第六课 EVT_ERASE_BACKGROUND背景擦除事件

时间:2017-08-09 16:55:58      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:background erase evt onerasebackground

说明

      默认情况下,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背景擦除事件

标签:background erase evt onerasebackground

原文地址:http://fengyuzaitu.blog.51cto.com/5218690/1954794

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!