简体   繁体   English

如何在wxListCtrl中设置sizer

[英]how to set sizer in wxListCtrl

I want to create a frame , which contains a panel and under that it has a wxListCtrl , when I minimize or maximize the frame, Listctrl is not dependent on Frame.so. 我想创建一个框架,其中包含一个面板,并且在其之下有一个wxListCtrl ,当我最小化或最大化框架时, Listctrl不依赖于Frame.so。 Can anybody tell me how I can make my wxListCtrl frame dependent. 谁能告诉我如何使wxListCtrl框架相关。 I know sizer will work here I used it, I think I used it in wrong way. 我知道sizer将在我使用过的地方工作,我认为我以错误的方式使用了它。 my code is: 我的代码是:

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


    }

It seems to me that you have not actually created a frame. 在我看来,您实际上尚未创建框架。 Though you inherited the wxFrame() class, you haven't created the frame. 尽管您继承了wxFrame()类,但尚未创建框架。 I would call 我会打电话给

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

before anything else to give you the frame first. 首先要给您框架。 Then it you might want to reference this frame with something like 然后,您可能想用类似以下内容引用此框架

Id_Search_Report *myFrame = this;

for clarity instead of using the this pointer and put your panel on top of this frame. 为了清楚起见,而不是使用this指针并将您的面板放在此框架的顶部。

hope that helps 希望能有所帮助

As I understand your queation you want to change the size of your controls as the size of the top fram is altered by the user. 据我了解,您想更改控件的大小,因为用户更改了顶部框架的大小。

To do this, you need to respond to sizer events generated when the fram changes size. 为此,您需要响应当fram更改大小时生成的sizer事件。 Something like this: 像这样:

EVT_SIZE(Id_Search_Report::OnSize)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM