| Back to logs list
3199545 2007 年 06 月 14 日 10:57 Reading (loading. ..) Comments (0) Category: vb.net
Calculation class preparation procedures are generally used to input text box digital data, this time through the following steps to ensure the accuracy of data entered by the user:
good first text box to add IMEMode TextBox control after the value of the property into Disable, so that the text box can not use Chinese input method. Then the text box KeyPress event,
paul smith handbags, add the following code
Private Sub TextBox1_KeyPress (ByVal sender As Object,
prada handbags, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char . IsDigit (e.KeyChar) Or e.KeyChar = Chr (8) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
which e . KeyChar is the keyboard key corresponding to the character, IsDigit function can determine whether the numbers 0 to 9,
miu miu handbags, Chr (8) for the backspace key when e.Handled is True, the program that the KeyPress event has been handled, , the contents of the text box will not change the. The program is easy to see from the above, then the text box only accept number and backspace key, which means that the text box is used to enter integers.
If the text need to enter decimal, then we would be able to enter the decimal point As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit (e.KeyChar) or e.KeyChar = Chr (8) or e. KeyChar = > 0 Then
e.Handled = True
; Else
e.Handled = False
; End If
Else
e.Handled = True
End If
End Sub
InStr function which returns the specified character position in the string when the string does not contain this character, returns a negative number. Then the text box can be used to enter a positive integer and decimal.
need to enter a negative number if the text, then we would be able to enter the minus sign > Private Sub TextBox1_KeyPress (ByVal sender As Object,
prada leather handbags, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit (e.KeyChar) Or e.KeyChar = ,
handbags uk, Else
e.Handled = False
End If
ElseIf e.KeyChar = e.Handled = False
Else
e.Handled = True
End If
End Sub
when the text box can be used to enter positive or negative integers and decimals.
When there are multiple text boxes enter the limit needs to be done, you can add the words in the above code Handles multiple text box KeyPress event, each event separated by commas, for example
Private Sub TextBox1_KeyPress (ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress, Textbox2.KeyPress,
burberry leather handbags, Textbox3.KeyPress
for the content of the text box to determine the function, we should modify the code so that it can handle multiple text boxes, that is, after the above two program TextBox1.Text to CType (sender, TextBox). Text, so to be able to condemnation, the example above, the code can enter a negative number can be changed to:
Private Sub TextBox1_KeyPress (ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress, Textbox2.KeyPress, Textbox3.KeyPress
If Char.IsDigit (e.KeyChar) Or e.KeyChar = . KeyChar = ; e.Handled = True
Else
; e.Handled = False
End If
ElseIf e.KeyChar = e.Handled = False
Else
e.Handled = True
End If
End Sub
to four text boxes so they all can only enter positive or negative integer and fractional out.