Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

UserControl Textbox

0.00/5 (No votes)
29 Jan 2008 1  
windows Textbox UserControl for only numeric, only alphbates, alphanumeric

Introduction

This is a reusable Custom Textbox control which will give you provision to enter only numeric values, only alphabetics and alphaNumeric values

Background

Public Class MyTextbox
    Enum opts
        numeric = 0
        charectors = 1
        both = 2
    End Enum
    Dim opt1 As opts
    Public Property options() As opts
        Get
            Return opt1
        End Get
        Set(ByVal value As opts)
            opt1 = value
        End Set
    End Property
    Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Select Case opt1
            Case opts.numeric
                If Char.IsDigit(e.KeyChar) = False Then
                    e.Handled = True
                End If
            Case opts.charectors
                If Char.IsLetter(e.KeyChar) = False Then
                    e.Handled = True
                End If
            Case opts.both
                If Char.IsLetterOrDigit(e.KeyChar) = False Then
                    e.Handled = True
                End If

        End Select
    End Sub
End Class

Points of Interest

.Net Windows Forms Textbox UserDefined Control

About the Author

Name:M.NareshKumar
Occupation:Senior Software Engineer
Company:Atherstone Consulting Limited.
Location:Hyderabad, India

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here