VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Disable Paste function for numeric text-box

by Gehan Fernando (47 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 4th March 2011
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Disable Paste function for numeric text-box

API Declarations


.Drawing

Rate Disable Paste function for numeric text-box




    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

Download this snippet    Add to My Saved Code

Disable Paste function for numeric text-box Comments

No comments have been posted about Disable Paste function for numeric text-box. Why not be the first to post a comment about Disable Paste function for numeric text-box.

Post your comment

Subject:
Message:
0/1000 characters