문제

i am trying to capture Function keys F1 to F12 & 4 Arrow Keys & Home, Insert, Delete, End, Page Up & Down Keys. How To ????

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
}
도움이 되었습니까?

해결책

Override the ProcessCmdKey() method of the form. It gets called straight from the message loop, before the keyboard message is dispatched to the control with the focus. Which is why overriding WndProc() doesn't work.

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == (Keys.Control | Keys.F)) {
            MessageBox.Show("What the Ctrl+F?");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Technically, you can also override the form's OnKeyDown method with KeyPreview = true, but that's an ugly VB6 anachronism.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top