1

我正在尝试捕捉快捷键。我需要解释如何KeyDown Events管理。让我们以此为例:

Private Sub SoldeOuvertFou_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    If e.Control And e.KeyCode = Keys.W Then
        MessageBox.Show("Ctrl+W")
        End If

    If e.Control And e.KeyCode = Keys.F5 Then
          MessageBox.Show("Ctrl+F5")
        End If

  End Sub

完美运行。无论我先按哪个或按多少次,它们MessageBox都会弹出。现在,如果我只是更改 sub 内的顺序:

Private Sub SoldeOuvertFou_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

    If e.Control And e.KeyCode = Keys.F5 Then
          MessageBox.Show("Ctrl+F5")
        End If

    If e.Control And e.KeyCode = Keys.W Then
        MessageBox.Show("Ctrl+W")
        End If

  End Sub

用这种方法,只会Ctrl+F5弹出。没有办法Ctrl+W出现......知道为什么吗?

4

1 回答 1

0

你可以简单地使用:

If e.Control Then

    If e.KeyCode = Keys.F5 Then
        MessageBox.Show("Ctrl+F5")
    Else
        If e.KeyCode = Keys.W Then
           MessageBox.Show("Ctrl+W")
        End If

    End If

End If
于 2013-04-11T13:31:11.757 回答