如何在wxwidgets中创建可调整大小的面板

How to create a resizable panels in wxwidgets?

本文关键字:可调整 创建 wxwidgets      更新时间:2023-10-16

我需要在一个框架中有3个面板,其中左面板和右面板应该由用户通过向左或向右拖动来调整。我已经使用AUI管理器完成了这一点,但我想在不使用AUI(可能是大小)的情况下做同样的事情。有什么办法做到这一点吗?我已经尝试了如下所示,但我无法调整面板的大小。

MyFrame1::MyFrame1(wxWindow* parent, wxwindowwid id, const wxString&title, const wxPoint&pos, const wxSize&size, long style): wxFrame(parent, id, title, pos, size, style){this->SetSizeHints(wxDefaultSize, wxDefaultSize);

wxBoxSizer* bSizer6;
bSizer6 = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxHORIZONTAL );
m_panel11 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
bSizer7->Add( m_panel11, 5, wxEXPAND | wxALL, 5 );

bSizer7->Add( 0, 0, 1, wxEXPAND, 5 );

bSizer6->Add( bSizer7, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer9;
bSizer9 = new wxBoxSizer( wxHORIZONTAL );
m_panel12 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
bSizer9->Add( m_panel12, 1, wxEXPAND | wxALL, 5 );

bSizer6->Add( bSizer9, 1, wxEXPAND, 5 );
wxBoxSizer* bSizer10;
bSizer10 = new wxBoxSizer( wxHORIZONTAL );
m_panel13 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
bSizer10->Add( m_panel13, 1, wxEXPAND | wxALL, 5 );

bSizer6->Add( bSizer10, 1, wxEXPAND, 5 );

this->SetSizer( bSizer6 );
this->Layout();
this->Centre( wxBOTH );

}

听起来你想使用的是wxSplitterWindow。您可以在http://docs.wxwidgets.org/3.0/classwx_splitter_window.html找到该类的文档。

MyFrame1::MyFrame1(wxWindow* parent, wxWindowID id, const wxString& title,
                     const wxPoint& pos, const wxSize& size, long style) :
        wxFrame(parent, id, title, pos, size, style)
{
    // use a base panel, so that you have the same background colour between controls
    // (panels in your case) too
    wxPanel* basePanel = new wxPanel(this);
    // create your controls; no need to add default values...
    m_panel11 = new wxPanel(basePanel);
    m_panel12 = new wxPanel(basePanel);
    m_panel13 = new wxPanel(basePanel);
    // create a sizer; one should be enough
    wxSizer* bSizer = new wxBoxSizer(wxHORIZONTAL);
    // add your controls to the sizer
    bSizer->Add(m_panel11, 1, wxEXPAND|wxALL, 5);
    bSizer->Add(m_panel12, 0, wxEXPAND|wxUP|wxDOWN|wxRIGHT, 5);
    bSizer->Add(m_panel13, 1, wxEXPAND|wxUP|wxDOWN|wxRIGHT, 5);
    // if you need different resizing proportion for each panel, read the description
    // of proportion parameter in wxSizer:Add() docs
    basePanel->SetSizer(bSizer);
}