Disable Paste function for numeric text-box
Disable Paste function for numeric text-box
API Declarations
.Drawing
Rate Disable Paste function for numeric text-box
(1(1 Vote))
Private Sub TextBoxNumeric_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles TextBoxNumeric.KeyPress
Dim digit As Char = e.KeyChar
If Char.IsDigit(digit) Or digit = ChrW(Keys.Back) Then
ReadOnlyText(TextBoxNumeric, False)
e.Handled = False
Else
If TextBoxNumeric.Text.Contains(".") = True Then
e.Handled = True
Else
If digit = Char.Parse(".") Then
ReadOnlyText(TextBoxNumeric, False)
e.Handled = False
Else
e.Handled = True
End If
End If
End If
End Sub
Private Sub ReadOnlyText(ByVal TxtBox As TextBox, Optional ByVal LockTextBox As Boolean = True)
Dim Clr As Color = TxtBox.BackColor
TxtBox.ReadOnly = LockTextBox
TxtBox.BackColor = Clr
End Sub
Private Sub TextBoxNumeric_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBoxNumeric.MouseDown
ReadOnlyText(TextBoxNumeric)
End Sub
End Class
Disable Paste function for numeric text-box Comments
No comments yet — be the first to post one!
Post a Comment