Winforms 如何设置CTRL+;Windows中的R按钮

Winforms 如何设置CTRL+;Windows中的R按钮,winforms,c#-3.0,Winforms,C# 3.0,我有下面的代码,当用户按下CTRL+R时,程序将被触发 public Form1() { InitializeComponent(); button1.KeyPress +=new KeyPressEventHandler(button1_KeyPress); } private void button1_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar == (char)Keys.Contro

我有下面的代码,当用户按下CTRL+R时,程序将被触发

public Form1()
 {
   InitializeComponent();
   button1.KeyPress +=new KeyPressEventHandler(button1_KeyPress);

 }

private void button1_KeyPress(object sender, KeyPressEventArgs e)
{

   if ((e.KeyChar == (char)Keys.ControlKey) && (e.KeyChar == (char)Keys.R))
   {
      MessageBox.Show("hello");
    }
}
但它不起作用。此外,如果按下“r”或“r”,则代码将运行不变

请帮助我犯错误的地方

谢谢。

试试这个:

private void button1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R)
            {
            }

        }

如果希望在用户按下某些组合键(如Ctrl+C或Ctrl+f)时通知应用程序,则需要重写ProcessCmdKey()方法。您可以找到有关此方法的更多信息

很抱歉,我无法理解您想要实现的目标。您想捕获按键事件吗?例如,复制时按住Ctrl+C键???但我遇到的是e.KeyCode==Keys.R部分,e.KeyCode值为“LButton | ShiftKey”,而对于Keys.R则为Keys.R。因此,代码不起作用