wxWidgets实战:wxRadioButton切换不同查找面板

先看看功能效果:

wxWidgets实战:wxRadioButton切换不同查找面板_第1张图片
wxWidgets实战:wxRadioButton切换不同查找面板_第2张图片

wxRadioButton

头文件:

#include 

函数:

m_rbtnMode1->GetValue()<<std::endl;
m_rbtnMode1->SetValue( true );       

创建radiobutton

 m_rbtnMode1 = new wxRadioButton( m_PanelAnalyse, wxID_ANY, _( "Based on Lookup Keyword,Model Name or Manufacturer PartNo." ), wxDefaultPosition, wxDefaultSize, 0 );

事件:
当 wxRadioButton 被选中时,它会触发wxEVT_RADIOBUTTON 事件。你可以捕获这个事件并在相应的事件处理函数中执行你想要的操作。
绑定事件

现在我有两个wxRaidoButton也想实现类似wxNoteBook的功能,切换不同wxRaidoButton显示不同page

#include 

class MyFrame : public wxFrame
{
public:
    MyFrame(const wxString& title)
        : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400, 300)
    {
        panelA = new wxPanel(this, wxID_ANY);
        panelB = new wxPanel(this, wxID_ANY);

        panelA->Hide();
        panelB->Hide();

        wxRadioButton* radioButtonA = new wxRadioButton(this, wxID_ANY, "Show Panel A", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
        wxRadioButton* radioButtonB = new wxRadioButton(this, wxID_ANY, "Show Panel B", wxDefaultPosition, wxDefaultSize);

        radioButtonA->Bind(wxEVT_RADIOBUTTON, &MyFrame::OnRadioButtonA, this);
        radioButtonB->Bind(wxEVT_RADIOBUTTON, &MyFrame::OnRadioButtonB, this);

        // Add controls to panel A
        wxStaticText* textA = new wxStaticText(panelA, wxID_ANY, "This is Panel A");
        wxButton* buttonA = new wxButton(panelA, wxID_ANY, "Button A");

        // Add controls to panel B
        wxStaticText* textB = new wxStaticText(panelB, wxID_ANY, "This is Panel B");
        wxButton* buttonB = new wxButton(panelB, wxID_ANY, "Button B");

        // Create sizers to arrange controls on each panel
        wxBoxSizer* sizerA = new wxBoxSizer(wxVERTICAL);
        sizerA->Add(textA, 0, wxALL, 5);
        sizerA->Add(buttonA, 0, wxALL, 5);
        panelA->SetSizer(sizerA);

        wxBoxSizer* sizerB = new wxBoxSizer(wxVERTICAL);
        sizerB->Add(textB, 0, wxALL, 5);
        sizerB->Add(buttonB, 0, wxALL, 5);
        panelB->SetSizer(sizerB);

        // Create a main sizer for the frame
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
        mainSizer->Add(radioButtonA, 0, wxALL, 5);
        mainSizer->Add(radioButtonB, 0, wxALL, 5);
        mainSizer->Add(panelA, 1, wxEXPAND | wxALL, 5);
        mainSizer->Add(panelB, 1, wxEXPAND | wxALL, 5);

        SetSizer(mainSizer);
    }

    void OnRadioButtonA(wxCommandEvent& event)
    {
        panelA->Show();
        panelB->Hide();
        Layout();
    }

    void OnRadioButtonB(wxCommandEvent& event)
    {
        panelA->Hide();
        panelB->Show();
        Layout();
    }

private:
    wxPanel* panelA;
    wxPanel* panelB;
};

class MyApp : public wxApp
{
public:
    virtual bool OnInit()
    {
        MyFrame* frame = new MyFrame("Radio Button Example");
        frame->Show(true);
        return true;
    }
};

wxIMPLEMENT_APP(MyApp);

你可能感兴趣的:(wxWidgets,kicad,wxWidgets,GUI,c++)