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

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章