如何在wxListCtrl中设置sizer

发布于 2024-10-18 07:22:06 字数 3862 浏览 4 评论 0原文

我想创建一个框架,其中包含一个面板,其下有一个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


    }

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. Can anybody tell me how I can make my wxListCtrl frame dependent.
I know sizer will work here I used it, I think I used it in wrong way. 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


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆头 2024-10-25 07:22:06

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

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

先打电话给你框架。然后,为了清楚起见,您可能需要使用类似的东西来引用该框架,

Id_Search_Report *myFrame = this;

而不是使用 this 指针,并将面板放在该框架的顶部。

希望有帮助

It seems to me that you have not actually created a frame. Though you inherited the wxFrame() class, you haven't created the frame. 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.

hope that helps

青瓷清茶倾城歌 2024-10-25 07:22:06

据我了解您的问题,您想要更改控件的大小,因为用户更改了顶部框架的大小。

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

EVT_SIZE(Id_Search_Report::OnSize)

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

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. Something like this:

EVT_SIZE(Id_Search_Report::OnSize)

void MyFrame::OnSize(wxSizeEvent& )
{
  if( data_list_control) {
    data_list_control->SetSize(GetClientRect());
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文