How to focus on a control in wxPanel when press a key  [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.
Ronald
Experienced Solver
Experienced Solver
Posts: 62
Joined: Mon Mar 05, 2018 4:17 am

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

Postby Ronald » Mon Aug 13, 2018 4:09 am

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
Experienced Solver
Experienced Solver
Posts: 62
Joined: Mon Mar 05, 2018 4:17 am

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

Postby Ronald » Mon Aug 13, 2018 5:10 am

EVT_CHAR_HOOK propagates to parent


Return to “C++ Development”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 20 guests