[英]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
I want to change the BackColor of the button if enter key is pressed but it does nothing when I pressed the enter key.如果按下回车键,我想更改按钮的背景颜色,但当我按下回车键时它什么都不做。 Form KeyPreview is set to true.If Enter key is replaced by another key the code is executed
Form KeyPreview 设置为 true。如果 Enter 键被另一个键替换,则执行代码
You can override ProcessCmdKey like this:您可以像这样覆盖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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.