Catching Ctrl + C in a textbox

后端 未结 8 1745
孤城傲影
孤城傲影 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:16

    For me, it's not working with KeyDown event so I tried with PreviewKeyDown and it's worked.

    private void txt_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
      if (e.Control == true && e.KeyCode == Keys.C)
      {
        Clipboard.SetText(txt.SelectedText);
      }
    }
    

提交回复
热议问题