How to cancel keyboard press/input in VB2008

Posted by Admin L in .NET Programming on 14-07-2011. Tags:

Author: Nosa Lee
Original Address: https://www.seeksunslowly.com/cancel-input-vb2008
To reprint this article, please indicate the source, thank you.
_____________________________________

Because it is different than VB6, so introduce it specially.
Method
Add the following code to the KeyPress event of the corresponding input control.
Sample Code
[cc lang=”vbnet”]
Private Sub cbPrompt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles cbPrompt.KeyPress
‘ Prevent inputting | symbol.
If e.KeyChar = “|” Then e.KeyChar = Chr(0)
End Sub
[/cc]

As above, it is usually used to prevent inputting specific characters in input fields (TextBox, ComboBox or others.

【赞赏 / Reward】

微信         支付宝         PayPal

Post a comment