键盘控制修饰符,数字问题

发布于 2025-02-03 22:45:28 字数 785 浏览 3 评论 0原文

我只想在用户按CTRL +1 .... n中的表单中的CTRL +1 .. NENCER中的字符1 ... n。如果为此使用按键事件:

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
        MessageBox.Show("KeyPress " + Keys.Shift);
    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
        MessageBox.Show("KeyPress " + Keys.Control);
}

如果我按Shift+1,则会在屏幕上看到消息“ Shift”。如果我按CTRL+1,则在屏幕上没有显示任何消息。例如,如果我按CTRL+B,这次我再次在屏幕上看到“控制”消息。因此,CTRL不适用于数字组合。

可以说,使用钥匙down方法,在这种情况下,只要我按住CTRL,就会运行该事件,这使我感到困扰。我想知道有没有办法用“按键”解决这个问题?

注意:我知道如何使用“ keydown”做到这一点:

if (Char.IsDigit(((char)e.KeyCode)) &&  e.Modifiers == Keys.Control)
{
     MessageBox.Show("KeyDown :" + ((char)e.KeyCode));
}

I simply want to get the character 1...n inside my function when the user presses ctrl +1....n in the form. if i use keypress event for this:

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
        MessageBox.Show("KeyPress " + Keys.Shift);
    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
        MessageBox.Show("KeyPress " + Keys.Control);
}

If I press Shift+1 I see the message "Shift pressed" on the screen. If I press ctrl+1, no message appears on the screen. For example, if I press ctrl+b, I see the "control pressed" message on the screen again this time. so ctrl doesn't work for combinations of numbers.

it can be said, use the keydown method, in that case the event is running as long as I hold down ctrl, which bothers me. I want to know is there a way to solve this with "keypress"?

note: I know how to do this with "keydown" :

if (Char.IsDigit(((char)e.KeyCode)) &&  e.Modifiers == Keys.Control)
{
     MessageBox.Show("KeyDown :" + ((char)e.KeyCode));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文