Please point me to some samples that update UI in a dialog. I would like to disable certain textctrls if the user clicks a checkbox.
Thanks,
Chris
UI Updating Topic is solved
Re: UI Updating
What's the part you're having problems with?
To disable a control, you call wxWindow::Disable()
https://docs.wxwidgets.org/trunk/classw ... f01f66c41e
To detect a click on a wxCheckBox, you catch the wxEVT_CHECKBOX event:
https://docs.wxwidgets.org/trunk/classwx_check_box.html
To disable a control, you call wxWindow::Disable()
https://docs.wxwidgets.org/trunk/classw ... f01f66c41e
To detect a click on a wxCheckBox, you catch the wxEVT_CHECKBOX event:
https://docs.wxwidgets.org/trunk/classwx_check_box.html
Use the source, Luke!
-
- Knows some wx things
- Posts: 25
- Joined: Sun Dec 11, 2022 6:00 pm
Re: UI Updating
I understand the references you've cited, but I'm having difficulty understanding where to place the code. So I thought an example or pseudo code would clear that up for me.
Re: UI Updating
cszalwinski wrote: ↑Mon Jan 23, 2023 5:12 pm I understand the references you've cited, but I'm having difficulty understanding where to place the code. So I thought an example or pseudo code would clear that up for me.
Code: Select all
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
wxIMPLEMENT_APP(MyApp);
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, "Minimal Sample")
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
m_checkbox = new wxCheckBox(panel, wxID_ANY, "enabled");
m_checkbox->SetValue(true);
m_checkbox->Bind(wxEVT_CHECKBOX, &MyFrame::OnCheckBox, this);
sizer->Add(m_checkbox, 0, wxEXPAND|wxALL, 4);
m_text = new wxTextCtrl(panel, wxID_ANY, "some text");
sizer->Add(m_text, 0, wxEXPAND|wxALL, 4);
panel->SetSizer(sizer);
};
void OnCheckBox( wxCommandEvent &evt )
{
m_text->Enable( m_checkbox->GetValue() );
m_text->Refresh(); // not always necessary, just to be safe
}
protected:
wxTextCtrl *m_text;
wxCheckBox *m_checkbox;
};
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
}
Use the source, Luke!
-
- Knows some wx things
- Posts: 25
- Joined: Sun Dec 11, 2022 6:00 pm
Re: UI Updating
Thank you! Works perfectly now. The Bind statement was missing in my logic.
Much appreciated,
Chris
Much appreciated,
Chris
Re: UI Updating
Hi,
If you don't call Bind() or don't use static event table, you program doesn't know anything about how to react to the event needed.
Bind() (and static event table macros) instructs you program what to do in case the particular event happens.
Thank you.
If you don't call Bind() or don't use static event table, you program doesn't know anything about how to react to the event needed.
Bind() (and static event table macros) instructs you program what to do in case the particular event happens.
Thank you.