 |
|
 |
|
Location: Blogs Andy's Blog |
|
| Posted by: host |
8/20/2004 8:56 AM |
Sometimes it's handy to create an inherited textbox that only accepts certain keys. For example, a textbox for inputing a monetary value. To do so, create a new user control, then change it's inherits clause to System.Windows.Forms.TextBox. You can then implement the KeyPress event to filter out any ANSI keyvalues. You can also implement the KeyDown event to handle other control keys such as the arrow keys.
Note that setting Handled = True will prevent the textbox from processing the key.
Private Sub ucTextBoxFilter_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
' allow only numerics
If Not IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub |
|
| Permalink |
Trackback |
|
|
 |
|
 |
|
|