单击任何按钮时如何取消激活输入密钥 [英] How do I deactive enter key when I click any button
本文介绍了单击任何按钮时如何取消激活输入密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了(0~9)个按钮,因为我想点击按钮(而不是在键盘上按下它)
ex:我点击btn5然后textbox1.text& =5
。但是当我点击任何按钮然后按下回车键(按钮将自动按下并且我不想要的东西)
我尝试了什么:
i只是通过点击按钮而不使用任何键(在键盘上)试图在文本框上书写
解决方案
你真的不应该这样做 - 这是Windows的默认行为和预期行为,你可能会面临危险。用户确实知道ENTER激活了一个按钮,如果你没有指定一个按钮来接受ENTER,那么当前聚焦的控件就会得到它。
最好的解决方案是让ENTER按下等于按钮 - 这很简单。
在你的表格中,覆盖ProcessCmdKey:
受保护的 覆盖 功能 ProcessCmdKey( ByRef msg 作为消息, ByVal keyData As Keys) As Boolean
如果 keyData = Keys.Enter 然后
buttonEquals.PerformClick()
返回 True
结束 如果
返回 MyBase .ProcessCmdKey(msg,keyData)
结束 功能跨度>
i made (0~9)buttons as i want to click the button (instead of pressing it on keyboard )
ex: i click on btn5 then textbox1.text &="5"
. but when i click on any button then press on enter key (the button will be pressed automatically and that what i do not want )
What I have tried:
i have tried to write on textbox just by click on buttons without using any keys (on keyboard)
解决方案
You really shouldn't do that - it is the default and expected behaviour for windows, and you mess with that at your peril. Users do know that ENTER activates a button, and if you don't specify a button to "accept" the ENTER, the currently focused control gets it.
The best solution would be to make ENTER press the "Equals" button - which is simple to do.
In your form, override ProcessCmdKey:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean If keyData = Keys.Enter Then buttonEquals.PerformClick() Return True End If Return MyBase.ProcessCmdKey(msg, keyData) End Function
这篇关于单击任何按钮时如何取消激活输入密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文