Click here to Skip to main content
Licence CPOL
First Posted 29 Jan 2008
Views 9,290
Downloads 23
Bookmarked 29 times

UserControl Textbox

By | 29 Jan 2008 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

nareshkumarmasetti

Web Developer
Atherstone Consulting Limited
India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberscarterszoo11:10 4 Apr '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 29 Jan 2008
Article Copyright 2008 by nareshkumarmasetti
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid