Catching Ctrl + C in a textbox

后端 未结 8 1735
孤城傲影
孤城傲影 2020-12-15 20:42

Despite me working with C# (Windows Forms) for years, I\'m having a brain fail moment, and can\'t for the life of me figure out how to catch a user typing Ctrl +

8条回答
  •  借酒劲吻你
    2020-12-15 21:25

    D'oh! Just figured it out. Out of the three possible events, the one I haven't tried is the one I needed! The KeyUp event is the important one:

    private void txtConsole_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyData == (Keys.C | Keys.Control))
        {
            _consolePort.Write(new byte[] { 3 }, 0, 1);
            e.Handled = true;
        }
    }
    

提交回复
热议问题