Search code examples
c++wxwidgets

How to get if User pressed Enter wxWidgets


I want to get the Input from a field

wxTextCtrl* upperOnly = new wxTextCtrl(this, wxID_ANY, wxT("Test"),wxPoint(5,260), wxSize(630,30));

and this i want every Time the user Pressed Enter


Solution

  • Use wxTE_PROCESS_ENTER when creating the control, i.e.

    wxTextCtrl* upperOnly = new wxTextCtrl(this, wxID_ANY, wxT("Test"),wxPoint(5,260), wxSize(630,30), wxTE_PROCESS_ENTER);
    

    Then catch wxEVT_TEXT_ENTER and do your validation in its event handler, i.e.

    upperOnly->Bind(wxEVT_TEXT_ENTER, [](wxCommandEvent&) {
            // Do something useful
         });