To Download Source Code Click Here > TextBox User Control
You can create your own Custom Text box and and Custom Properties and select the Custom Text box's properties as per your requirement.
Lets Start...
- Open Visual Studio and open new Project under Visual basic, Windows form Template.
- Now right click in the solution explorer, click on add, click on User Control, which will give you a blank form without any boarder.
- Now add a Text Box Control to that form, and re-size the form according to the size of the Text box Control.
Public Class MyTextbox
Enum txt
Numeric
Alphabet
AlphaNumeric
End Enum
Dim txtbx As txt = txt.Alphabet
Property txtStyle() As txt
Get
Return txtbx
End Get
Set(ByVal Value As txt)
txtbx = Value
End Set
End Property
Private Sub TextBox1_KeyPress(ByVal Sender As Object, ByVal e As System.Windows.Forms.keyPressEventArgs) Handles TextBox1.KeyPress
Select Case txtbx
Case txt.Numeric
Textbox1.MaxLength = 11
If Char.IsDigit(e.KeyChar) Or Asc(e.KeyChar) = 8 Or TextBox1.MaxLength > 11 Then
Else
e.Handled = True
End If
Case txt.Alphabet
Textbox1.MaxLength = 11
If Char.IsAlphabet(e.KeyChar) Or Char.IsWhiteSpase(e.KeyChar) Or Asc(e.KeyChar) = 8 Or TextBox1.MaxLength > 20 Then
Else
e.Handled = True
End If
Case txt.AlphaNumeric
Textbox1.MaxLength = 11
If Char.IsAlphaNumeric(e.KeyChar) Or Char.IsWhiteSpase(e.KeyChar) Or Asc(e.KeyChar) = 8 Or TextBox1.MaxLength > 50 Then
Else
e.Handled = True
End If
End Select
End Sub
End Class
5. Go to Build Menu and Click on Build "Your Project Name"
6. Go to Solution Explorer right Click on Form1 and Click on View Designer.
7. Place three Labels and Set its Text Properties to Name, Address, Mobile Accordingly.
8. Now go to Tool Box you will find a new Control added to Your tool Box at the top, ad three of that new tool to your form and set its property as per your need.
9. Now press F5 key from the keyboard and try entering the values to the text box.
Thats all...
Help From : http://www.codeproject.com/KB/vb/customTextBox.aspx.aspx