show/hide button with sizers

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
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

show/hide button with sizers

Post by mazeem3 »

This might be a stupid question.

How do I hide a button by using sizers

Code: Select all

vbox->Add(Grid,wxID_ANY, wxEXPAND | wxALL);
vbox->Add(hbox,0, wxEXPAND| wxALL | wxBOTTOM);

hbox->Add(ButtonRemoveDataFile);
ButtonRemoveDataFile->Hide();
Panel->SetSizer(vbox);
this->SetMinSize(wxSize(400, 300));
The button is still displayed even after i call Hide()
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: show/hide button with sizers

Post by ONEEYEMAN »

Hi,
You need to call Layout after hiding.
And you don't have to play with sizes. Layout will re-position everything for you.

Thank you.
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Re: show/hide button with sizers

Post by mazeem3 »

Code: Select all

	vbox->Add(Grid,wxID_ANY, wxEXPAND | wxALL);
    vbox->Add(hbox,0, wxEXPAND| wxALL | wxBOTTOM);

    hbox->Add(ButtonRemoveDataFile);
    ButtonRemoveDataFile->Hide();
    vbox->Layout();
	Panel->SetSizer(vbox);
	this->SetMinSize(wxSize(400, 300));
I added called layout but doesnt seem to make a difference
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: show/hide button with sizers

Post by ONEEYEMAN »

Hi,
Try this:

Code: Select all

vbox->Add(Grid,wxID_ANY, wxEXPAND | wxALL);
vbox->Add(hbox,0, wxEXPAND| wxALL | wxBOTTOM);
hbox->Add(ButtonRemoveDataFile, 0, wxEXPAND, 0);
ButtonRemoveDataFile->Hide();
Panel->SetSizer(vbox);
this->SetMinSize(wxSize(400, 300));
Layout();
I presumed that "Panel" is an object of type wxPanel, and "this" pointer is wxDialog-based class.

Thank you.
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Re: show/hide button with sizers

Post by mazeem3 »

Still no change.

Yes panel is an object of type wxPanel, and this is a pointer to the wxFrame-based class

would that make a difference on the Hide() function?
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Re: show/hide button with sizers

Post by mazeem3 »

I figured it out. Thanks for your help.

My button is attached to the panel

Code: Select all

    ButtonRemoveDataFile = new wxButton(Panel, ID_BUTTON_REMOVE_DATA_FILE, _("Remove Data File from Project"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON_REMOVE_DATA_FILE"));
so i have to call

Code: Select all

Panel->Layout();
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: show/hide button with sizers

Post by ONEEYEMAN »

Hi,
Do you want the button to be initially hiding?
What version of wx and what OS/toolkit version you are using?

Thank you.

P.S.: Glad it is solved. ;-)
mazeem3
Earned a small fee
Earned a small fee
Posts: 17
Joined: Fri Jul 14, 2017 6:12 pm

Re: show/hide button with sizers

Post by mazeem3 »

yes i want the button initially hidden and if someone selects a grid cell then i want it to show

wxWidget 3.1.0/ Windows 7 64-Bit OS
Post Reply