closing frame

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
disin
In need of some credit
In need of some credit
Posts: 9
Joined: Sat Apr 06, 2019 4:46 am

closing frame

Post by disin »

Code: Select all


MyFrame::MyFrame(const wxString &Title):wxFrame(NULL,MyFrame_ID,wxT("parent Frame"),wxDefaultPosition,wxSize(1000,700))
{
Connect(ID_CNR,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MyFrame::OnChoice1));
}


void MyFrame::OnChoice1(wxCommandEvent &Event)
{
Frame2=new wxFrame(this,20,wxT("Frame2"),wxDefaultPosition,wxSize(400,300));
Frame2->Show(true);
Connect(ID_CREATE,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MyFrame::CreateRecord));
}

void MyFrame::CreateRecord(wxCommandEvent &event)
{
    Frame2->Destroy();	
}
Frame2->Destroy() closes "parentFrame"
i only wanted to close the Frame2 not the parentFrame
how am i going to close only the Frame2
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 469
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: closing frame

Post by New Pagodi »

I'm pretty sure your program is crashing. According to the documentation for connect, you need to supply a data object and an event handler or NULL will be used by default. So

Code: Select all

Connect(ID_CNR,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MyFrame::OnChoice1),NULL,this);
and

Code: Select all

Connect(ID_CREATE,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(MyFrame::CreateRecord),NULL,this);
By the way, for new code, you should use Bind instead of Connect. That way you don't have to cast the method and some errors can be caught at compile time.
Post Reply