如何在VB中使用keypress?

2025-05-18 03:00:00
推荐回答(1个)
回答1:

  代码如下:
  Visual Basic code
  Private Sub GcTextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles GcTextBox2.KeyPress
  '单独判断回车
  Dim a As Char = Convert.ToChar(Keys.Enter)
  If e.KeyChar.Equals(a) Then
  MessageBox.Show("Enter Press")
  End If
  '判断CTRL+回车
  If (Control.ModifierKeys And Keys.Shift) = Keys.Shift Then
  Dim aa As Char = Convert.ToChar(Keys.Return)
  If e.KeyChar = aa Then
  MessageBox.Show("Control+Enter Press")
  End If
  End If
  End Sub