VB2008 中取消键盘输入的方法
Posted by Admin L in .NET Programming on 14-07-2011. Tags: .NET 编程经验
作者:牧山道人
原文地址:https://www.seeksunslowly.com/cancel-input-vb2008-sc
转载请注明出处,谢谢。
_____________________________________
因为与 VB6 略有不同,故单独说明一下。
方法
在相应输入控件的 KeyPress 事件中加入以下代码即可。
示例代码
[cc lang=”vbnet”]
Private Sub cbPrompt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles cbPrompt.KeyPress
‘ 禁止输入 | 符号。
If e.KeyChar = “|” Then e.KeyChar = Chr(0)
End Sub
[/cc]
如上,一般在输入域(TextBox、ComboBox)中禁止输入某(些)字符时特有用。


