Make sure the text box input value code

xiaoxiao2021-03-06  15

When a text box can only enter numbers, we need to limit to avoid operators entering other characters, so as to avoid error, the following code can achieve such an effect.

We assume that the text box name is: txtweight, write the following code in the keypress event.

'The following code is allowed to enter numbers and decimal points

Private sub txtweight_keypress (Byval e as system.windows.forms.keypressEventArgs) Handles TxtWeight.KeyPress

Ifchar.isnumber (e.keychar) or E.Keychar = chr (keys.back) or e.keychar = "." THEN RETURN End if E.handled = true

End Sub

'When you save the data, you need to check this text box: First, check if the operator is entered, and the other is to check if the operator has entered a valid number, then we can add the detection code in front of the save event:

If Trim (Me.txtWeight.text) = "" "" "" "" ", please enter the order quantity!", SoftName, MessageBoxButtons.ok, MessageBoxicon.information) me.txtweight.focus () EXIT SUB END IF

IF isnumeric (me.txtweight.text) = false the messagebox.show ("Order Quantity Input Error", SoftName, MessageBoxButtons.ok, MessageBoxicon.exclamation) Me.txtWeight.focus () EXIT SUB End IF

转载请注明原文地址:https://www.9cbs.com/read-45823.html

New Post(0)