wxWidgets第八课 wxControl自定义控件

说明

    从wxControl中派生出一个控件,调用OnPaint函数对控件进行渲染

例子


头文件

#include "wx/bitmap.h"

#include "wx/control.h"

#include "wx/dcclient.h"


声明

class CFlightInstrumentCompass : public wxControl

{

private:

DECLARE_DYNAMIC_CLASS(CFlightInstrumentCompass)

DECLARE_EVENT_TABLE()


public:

CFlightInstrumentCompass() {Init();}

void Init() {}


CFlightInstrumentCompass(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator)

{

Init();

Create(parent, id, pos, size, style, validator);

}


bool Create(wxWindow *parent,

wxWindowID id,

const wxPoint& pos = wxDefaultPosition,

const wxSize& size = wxDefaultSize,

long style = 0,

const wxValidator& validator = wxDefaultValidator);

~CFlightInstrumentCompass(void);


protected:

void OnPaint(wxPaintEvent& event);

};


定义


BEGIN_EVENT_TABLE(CFlightInstrumentCompass, wxControl)

EVT_PAINT(CFlightInstrumentCompass::OnPaint)

END_EVENT_TABLE()

IMPLEMENT_DYNAMIC_CLASS(CFlightInstrumentCompass, wxControl)


void CFlightInstrumentCompass::OnPaint( wxPaintEvent& event )

{

}


提醒

    为了减少闪烁,重写OnEraseBackground函数,并且留空,说明不再需要擦除背景


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





上一篇:实体商家如何利用数据突破上升瓶颈 ——云栖大会精彩演讲复盘,小白也能看的懂


下一篇:深圳云栖大会人工智能专场:探索视频+AI,玩转智能视频应用