Catching Ctrl + C in a textbox

后端 未结 8 1733
孤城傲影
孤城傲影 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条回答
  •  Happy的楠姐
    2020-12-15 21:31

    Go ahead and use the KeyDown event, but in that event check for both Ctrl and C, like so:

    if (e.Control && e.KeyCode == Keys.C) {
        //...
        e.SuppressKeyPress = true;
    }
    

    Also, to prevent processing the keystroke by the underlying TextBox, set the SuppressKeyPress property to true as shown.

提交回复
热议问题