在键盘中按下 Enter 时更改按钮的背景颜色
Changing backColor of button when pressed Enter in keyboard
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Button1.BackColor = Color.Aqua
End If
End Sub
我想在按下回车键时更改按钮的背景颜色,但当我按下回车键时它什么也没做。表单 KeyPreview 设置为 true.If Enter 键被另一个键替换 代码被执行
您可以像这样覆盖 ProcessCmdKey:
Public Class Form1
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = Keys.Enter Then
Button1.BackColor = Color.Aqua
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Button1.BackColor = Color.Aqua
End If
End Sub
我想在按下回车键时更改按钮的背景颜色,但当我按下回车键时它什么也没做。表单 KeyPreview 设置为 true.If Enter 键被另一个键替换 代码被执行
您可以像这样覆盖 ProcessCmdKey:
Public Class Form1
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = Keys.Enter Then
Button1.BackColor = Color.Aqua
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
End Class