如何在wxListCtrl中设置sizer

时间:2011-02-19 09:56:35

标签: c++ wxwidgets

我想创建一个包含面板的框架,在它下面有一个wxListCtrl,当我最小化或最大化框架时,Listctrl不依赖于Frame.so。任何人都可以告诉我如何使我的wxListCtrl帧依赖。 我知道sizer会在这里工作我使用它,我想我用错了它。我的代码是:

Id_Search_Report::Id_Search_Report(const wxString &title)
      :wxFrame (NULL,1,title,wxDefaultPosition,wxSize(985,650),wxDEFAULT_FRAME_STYLE)
    {
/*
\---------------------------------------------------------------------------------
              INITIALIZAION OF COUNTER WITH 0
---------------------------------------------------------------------------------
*/
        this->counter=0;
/*
---------------------------------------------------------------------------------
              CALLING PANEL CONSTRUCTOR
---------------------------------------------------------------------------------
*/
        panel_first =new wxPanel(this, wxID_ANY, wxDefaultPosition,  wxDefaultSize, wxTAB_TRAVERSAL,wxT(""));
        wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
                panel_first->SetSizer(vbox);

/*
---------------------------------------------------------------------------------
              CALLING LIST CONTROL CONSTRUCTOR
---------------------------------------------------------------------------------
*/
        data_list_control= new wxListCtrl(panel_first, wxID_ANY, wxPoint(0,0), wxDefaultSize, wxLC_REPORT,wxDefaultValidator);
        vbox->Add(data_list_control,1,wxEXPAND);

/*
---------------------------------------------------------------------------------
               CALLING CLOSE BUTTON CONSTRUCTOR
---------------------------------------------------------------------------------
*/
        submit=new wxButton(panel_first,41,BUTTON_CLOSE ,wxPoint(880,620), wxDefaultSize);
        back =new wxButton(panel_first, 42,BUTTON_BACK ,wxPoint(880,630), wxDefaultSize);
/*
---------------------------------------------------------------------------------
               CREATING EVENT FOR CLOSE BUTTON CLICKED
---------------------------------------------------------------------------------
*/
        Connect(41, wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(Id_Search_Report::onbuttonclick));
/*
---------------------------------------------------------------------------------
               INITIALIZATION OF LIST CONTROL COLOUMN
               INSERT COLOUMN PARAMETERS ARE:-(ID, HEADER TEXT, ALLIGNMENT(2 FOR MIDDLE)
---------------------------------------------------------------------------------
*/
        data_list_control->InsertColumn(0,COLOUMN_1,2);
        //data_list_control->SetColumnWidth(0, 80);
        data_list_control->InsertColumn(1,COLOUMN_2,2);
        //data_list_control->SetColumnWidth(1, 80);
        data_list_control->InsertColumn(2,COLOUMN_3,2);
        //data_list_control->SetColumnWidth(2, 80);
        data_list_control->InsertColumn(3,COLOUMN_4,2);
        //data_list_control->SetColumnWidth(3, 80);
        data_list_control->InsertColumn(4,COLOUMN_5,2);
        //data_list_control->SetColumnWidth(4, 80);
        data_list_control->InsertColumn(5,COLOUMN_6,2);
        //data_list_control->SetColumnWidth(5, 80);
        data_list_control->InsertColumn(6,COLOUMN_7,2);
        //data_list_control->SetColumnWidth(6, 80);
        data_list_control->InsertColumn(7,COLOUMN_8,2);
        //data_list_control->SetColumnWidth(7, 80);
        data_list_control->InsertColumn(8,COLOUMN_9,2);
        //data_list_control->SetColumnWidth(8, 80);
        data_list_control->InsertColumn(9,COLOUMN_10,2);
        //data_list_control->SetColumnWidth(9, 80);
        data_list_control->InsertColumn(10,COLOUMN_11,2);
        //data_list_control->SetColumnWidth(10, 80);
        data_list_control->InsertColumn(11,COLOUMN_12,2);
        //data_list_control->SetColumnWidth(11, 80);
        //sizer


    }

2 个答案:

答案 0 :(得分:0)

在我看来,你实际上并没有创建一个框架。虽然您继承了wxFrame()类,但尚未创建框架。我会打电话给

 wxFrame::Create( parent, id, caption, pos, size, style )

之前先给你一个框架。然后你可能想要用

之类的东西来引用这个框架
Id_Search_Report *myFrame = this;

为了清晰起见而不是使用这个指针并将你的面板放在这个框架的顶部。

希望有所帮助

答案 1 :(得分:0)

据我了解您的排队时,您想要更改控件的大小,因为用户会更改顶级框架的大小。

为此,您需要响应fram更改大小时生成的sizer事件。像这样:

EVT_SIZE(Id_Search_Report::OnSize)

void MyFrame::OnSize(wxSizeEvent& )
{
  if( data_list_control) {
    data_list_control->SetSize(GetClientRect());
  }
}