How to focus on a control in wxPanel when press a key Topic is solved

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
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

How to focus on a control in wxPanel when press a key

Post by Ronald »

For example, there are some text ctrls and buttons in a panel(wxPanel), what's need is: Press F1 to focus on a specific text ctrl.

The code below doesn't work, OnChar is never executed.

Code: Select all

BEGIN_EVENT_TABLE(MainPanel, wxPanel)
EVT_CHAR(MainPanel::OnChar)
END_EVENT_TABLE()

void MainPanel::OnChar(wxKeyEvent & event)
{
    switch (event.GetKeyCode())
    {
    case WXK_F1:
        pTextCtrl->SetFocus();
        break;
    default:
        event.Skip();
        break;
    }
}
Ronald
Super wx Problem Solver
Super wx Problem Solver
Posts: 306
Joined: Mon Mar 05, 2018 4:17 am

Re: How to focus on a control in wxPanel when press a key

Post by Ronald »

EVT_CHAR_HOOK propagates to parent
Post Reply