Push OK button when pressing enter
koen at vermeer.tv
koen at vermeer.tv
Tue Dec 4 05:26:34 PST 2007
Hi,
I'm sure this is a FAQ (it feels like it's simple, but I just cannot find
a way to accomplish it), but here it goes anyway: On a wxDialog, how do I
set up things in such a way that when the user presses Enter, the OK
button is pushed? Right now, Enter just works like tab, moving from one
control to the next one, until it reaches the OK button. Then, another
enter pushes the button.
My code for the wxDialog constructor (created by wxSmith) is:
wxBoxSizer* BoxSizer1;
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE, _T("id"));
SetClientSize(wxDefaultSize);
Move(wxDefaultPosition);
BoxSizer1 = new wxBoxSizer(wxVERTICAL);
TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, _("Text"),
wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
_T("ID_TEXTCTRL1"));
BoxSizer1->Add(TextCtrl1, 1,
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, _("Text"),
wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
_T("ID_TEXTCTRL2"));
BoxSizer1->Add(TextCtrl2, 1,
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StdDialogButtonSizer1 = new wxStdDialogButtonSizer();
StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_OK,
wxEmptyString));
StdDialogButtonSizer1->AddButton(new wxButton(this, wxID_CANCEL,
wxEmptyString));
StdDialogButtonSizer1->Realize();
BoxSizer1->Add(StdDialogButtonSizer1, 1,
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Thanks!
Koen
More information about the wx-users
mailing list