【发布时间】:2014-08-16 05:01:52
【问题描述】:
我正在尝试获得一个滚动面板,我可以在其中像在 MS Paint 上一样绘制图片
问题是,当我画一些东西来尝试应用程序时:
- 我画了一个(或多个)矩形
- 我向右滚动面板,矩形仍然在左侧
- 我将面板向左滚动,矩形消失了
我是 wx 的新手,我想我错过了一些重要的事情
在 Codelite (C++)、Windows 7 32 位中使用 wxWidget
代码如下:
editorshp.h
class EditorShp : public wxFrame {
protected:
wxClientDC *dcPannelloDisegno;
wxScrolledWindow *scrollwin;
wxPanel *pannello;
public:
EditorShp( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Editor SHP"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,500 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
void draw_temp(wxCommandEvent& WXUNUSED(event));
};
editorshp.cpp
PS:bDrawTemp 是我用来绘制一些矩形的按钮(第一个在点 100,100;第二个在点 200,100,依此类推)
EditorShp::EditorShp( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) {
scrollwin = new wxScrolledWindow(this, -1, wxPoint(0, 0), wxSize(700, 400));
scrollwin->SetScrollbars(1, 1, 1600, 1000, 0, 0);
pannello = new wxPanel(scrollwin, -1, wxPoint(0, 0), wxSize(700, 400), wxFULL_REPAINT_ON_RESIZE);
dcPannelloDisegno = new wxClientDC(pannello);
scrollwin->DoPrepareDC(*dcPannelloDisegno);
wxButton *bDrawTemp= new wxButton( this, wxID_ANY, _("Indietro"), wxPoint(0, 400), wxSize( 100, 24 ), 0 );
bDrawTemp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(EditorShp::disegnaTemp), NULL, this);
scrollwin->Show(true);
this->Show(true);
}
void EditorShp::draw_temp(wxCommandEvent& WXUNUSED(event)){
static int x = 100, y = 100;
dcPannelloDisegno->DrawRectangle(wxPoint(x, y), wxSize(10, 10));
//pannello->Refresh(); it cancels everything
pannello->Update();
x += 100;
x = x % 1600;
}
编辑 1: 抱歉,这不是 wxScrollingPanel,而是 wxScrolledWindow
【问题讨论】:
-
如果我添加连接到 wxClientDC 的 wxBufferedDC 什么都不会发生...我必须使用 wxPaintDC 吗?
标签: c++ scroll panel wxwidgets