Page 1 of 1

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

Posted: Mon Aug 13, 2018 4:09 am
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;
    }
}

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

Posted: Mon Aug 13, 2018 5:10 am
by Ronald
EVT_CHAR_HOOK propagates to parent