我假装"抓住"并处理事件:来自wxTextCtrl的EVT_TEXT和来自wxID_APPLY的EVT_BUTTON。
我尝试用事件表处理事件,我不能?为什么呢?
源代码:
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class Dialog : public wxDialog
{
public:
Dialog(wxWindow *parent, const wxString &title);
private:
void OnNameChange(wxCommandEvent &event);
void OnApply(wxCommandEvent &event);
wxDECLARE_EVENT_TABLE();
wxTextCtrl *m_name;
};
enum
{
ID_NAME = 1
};
Dialog::Dialog(wxWindow *parent, const wxString &title) :
wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
SetSizer(vbox);
wxFlexGridSizer *flexGrid = new wxFlexGridSizer(2, 2, 5, 5);
wxStaticText *label = new wxStaticText(this, wxID_ANY, "&Name:");
flexGrid->Add(label);
m_name = new wxTextCtrl(this, ID_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
flexGrid->Add(m_name, 1, wxEXPAND);
label = new wxStaticText(this, wxID_ANY, "&Description:");
flexGrid->Add(label);
m_description = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
flexGrid->Add(m_description, 1, wxEXPAND);
flexGrid->AddGrowableRow(1, 1);
flexGrid->AddGrowableCol(1, 1);
vbox->Add(flexGrid, 1, wxALL | wxEXPAND, 15);
vbox->Add(CreateSeparatedButtonSizer(wxAPPLY | wxCANCEL), 0, wxEXPAND | wxALL, 5);
}
void Dialog::OnNameChange(wxCommandEvent &event)
{
m_description->AppendText("Hello\n");
}
void Dialog::OnApply(wxCommandEvent &event)
{
m_description->AppendText("Apply\n");
}
wxBEGIN_EVENT_TABLE(Dialog, wxDialog)
EVT_TEXT(ID_NAME, Dialog::OnNameChange)
EVT_BUTTON(wxID_APPLY, Dialog::OnApply)
wxEND_EVENT_TABLE()
只能动态处理事件吗?
Bind(wxEVT_TEXT, &Dialog::OnNameChange, this, m_name->GetId());