Posted By

indra on 10/19/10


Tagged

textBox


Versions (?)

Textbox Numeric Input


 / Published in: VB.NET
 

  1. ' Number with comma
  2. Private Sub NumberTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumberTextBox.KeyPress
  3. Dim tb As TextBox = sender
  4.  
  5. If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or (e.KeyChar = "," And tb.Text.IndexOf(",") < 0)) Then
  6.  
  7. e.Handled = True
  8.  
  9. End If
  10.  
  11. End Sub
  12.  
  13. ' Just Number
  14. Private Sub NumberTextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumberTextBox.KeyPress
  15. Dim tb As TextBox = sender
  16.  
  17. If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
  18.  
  19. e.Handled = True
  20.  
  21. End If
  22.  
  23. End Sub

Report this snippet  

You need to login to post a comment.