GridBagSizer 是一款多功能的sizer。它提供了比FlexiGridSizer更多的增强功能。
子窗口小部件 可以添加到网格中的特定单元格。
子窗口小部件可以水平和/或垂直占用多个单元。因此,同一行中的静态文本和多行文本控件可以具有不同的宽度和高度。
wxGBPosition 网格中行和列的位置
wxSpan 跨越的行和列
class LayoutGridbagSizer:public wxFrame
{
public:
LayoutGridbagSizer(const wxString& title);
};
LayoutGridbagSizer::LayoutGridbagSizer(const wxString& title)
:wxFrame(NULL,-1,title,wxPoint(-1,-1),wxSize(-1,-1))
{
wxGridBagSizer *sizer = new wxGridBagSizer(0,0);
wxStaticText *stName = new wxStaticText(this,wxID_ANY,"Name:");
sizer->Add(stName,wxGBPosition(0,0),wxDefaultSpan, wxALL,5);
wxTextCtrl *txtName = new wxTextCtrl(this,wxID_ANY);
sizer->Add(txtName,wxGBPosition(0,1),wxDefaultSpan,wxEXPAND|wxALL,5);
wxStaticText *stAddress = new wxStaticText(this,wxID_ANY,"Address:");
sizer->Add(stAddress,wxGBPosition(1,0),wxDefaultSpan,wxALL,5);
wxTextCtrl *txtAddress = new wxTextCtrl(this,wxID_ANY,""
,wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
);
sizer->Add(txtAddress,wxGBPosition(1,1),
wxGBSpan(1,3),//跨3列
wxEXPAND|wxALL,5);
wxStaticText *stAge = new wxStaticText(this,wxID_ANY,"Age:");
sizer->Add(stAge,wxGBPosition(2,0),wxDefaultSpan,wxALL,5);
wxTextCtrl *txtAge = new wxTextCtrl(this,wxID_ANY);
sizer->Add(txtAge,wxGBPosition(2,1),wxDefaultSpan,wxEXPAND|wxALL,5);
wxStaticText *stMobNo = new wxStaticText(this,wxID_ANY,"Mob.No:");
sizer->Add(stMobNo,wxGBPosition(2,2),wxDefaultSpan,wxALL,5);
wxTextCtrl *txtMobNo = new wxTextCtrl(this,wxID_ANY);
sizer->Add(txtMobNo,wxGBPosition(2,3),wxDefaultSpan,wxEXPAND|wxALL,5);
wxStaticText *stDesc = new wxStaticText(this,wxID_ANY,"Description:");
sizer->Add(stDesc,wxGBPosition(3,0),wxDefaultSpan,wxALL,5);
wxTextCtrl *txtDesc = new wxTextCtrl(this,wxID_ANY,""
,wxDefaultPosition
,wxDefaultSize,
wxTE_MULTILINE
);
sizer->Add(txtDesc,wxGBPosition(3,1),wxGBSpan(1,3),wxEXPAND|wxALL,5);
wxButton *btnOK= new wxButton(this,wxID_ANY,"OK");
sizer->Add(btnOK,wxGBPosition(4,2),wxDefaultSpan,wxALL|wxALIGN_RIGHT,5);
wxButton *btnClose = new wxButton(this,wxID_ANY,"Close");
sizer->Add(btnClose,wxGBPosition(4,3),wxDefaultSpan,wxALL|wxALIGN_RIGHT,5);
sizer->AddGrowableRow(1);//第1行可增长
sizer->AddGrowableRow(3);//第3行可增长
sizer->AddGrowableCol(1);//第2列可增长
sizer->AddGrowableCol(3);//第2列可增长
SetSizerAndFit(sizer);
// wxBoxSizer *bsMain = new wxBoxSizer(wxHORIZONTAL);
// bsMain->Add(sizer,1,wxEXPAND|wxALL,10);
// SetSizerAndFit(bsMain);
Center();
}