如何创建派生类的小部件(按钮)

问题描述 投票:1回答:1

我是新手,正在设计wxwidgets和c ++,在本主题中,我想问一下如何创建派生类(继承MainFrame类的APMainFrame)形式的小部件(按钮)

Code MainFrame GUI:] >>

MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) );
    .....
    this->SetMenuBar( m_menubar1 );
    this->Centre( wxBOTH );
}

和APMainFrame.h代码:

class APMainFrame : public MainFrame
{
    public:
        /** Constructor */
        APMainFrame( wxWindow* parent );
    //// end generated class members
        wxButton* HelloWorld; // here i wanna create function and button for GUI
        void OnExit(wxCommandEvent& event);
private:
        DECLARE_EVENT_TABLE()
};

enum
{
    BUTTON_Hello = wxID_HIGHEST + 1 
};

和文件APMainFrame.cpp:

BEGIN_EVENT_TABLE(APMainFrame, MainFrame)
EVT_BUTTON(BUTTON_Hello, APMainFrame::OnExit) 
END_EVENT_TABLE() // The button is pressed

APMainFrame::APMainFrame( wxWindow* parent )
:
MainFrame( parent )
{
    HelloWorld = new wxButton(this, BUTTON_Hello, _T("Hello World"),
        // shows a button on this window
        wxDefaultPosition, wxDefaultSize, 0); 

}

void APMainFrame::OnExit(wxCommandEvent& event)
{
    Close(TRUE);
}

我只想创建Widget形式的Drived类。非常感谢。

我是新手,正在设计wxwidgets和c ++,在本主题中,我想问一下如何创建派生类(继承MainFrame类的APMainFrame)形式的小部件(按钮)代码MainFrame GUI:MainFrame :: ...

c++ user-interface wxwidgets
1个回答
0
投票

您需要在wxPanel派生帧中添加面板(wxFrame)和大小调整器。

您已经创建了按钮,但是您还需要将其添加到框架中,以便它知道如何渲染它。

© www.soinside.com 2019 - 2024. All rights reserved.