ARTICLE

MaskedTextBox control in VB.NET

Posted by Dea Saddler Articles | ASP.NET using VB.NET March 31, 2011
In this article we demonstrate on what is MaskedTextBox,its properties and how can you use this MaskedTextBox control.
Download Files:
 
Reader Level:


A visual basic MaskedTextBox control provides validation mechanism for user input on a form. It is the best way to stop users from entering invalid data into an input control. The MaskedTextBox control constrains the format of user input by distinguishing between proper and improper user input. The Mask property of the MaskedTextBox control allow you to specify whether input characters are letters or numbers, as well as any formatting.



Properties of MaskedTextBox control:-

  • AccessibilityObject:- Determines the AccessibilityObject assigned to the control. 
  • AccessibleRole:- Determines the accessible Role of the control.
  • AutoScrollOffset:- Determines where this control Scrolled to in ScrollControlIntoView. 
  • BackColor:- Determines the background color of the control. 
  • BindingContext:- Determines BindingContext of the control.

     

How to use MaskedTextBox Control
  • Open a new project. 
  • Drag two MaskedTextBox, Label, Buttons on form. Form will display like below.

    MaskedTextBox1.gif
     
  • Change the class name to frmMain and write the below code.

        
    Private Sub mtbMaskTest_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtbMaskTest.GotFocus
            'Set mask in test control
            mtbMaskTest.Mask = txtMask.Text
            'Select all to ease data entry
            mtbMaskTest.SelectAll()
        End Sub
        Private Sub btnTestMask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestMask.Click
            'Test if mask data entry completed
            If mtbMaskTest.MaskCompleted Then
                MessageBox.Show("Entry in mask is valid", "Valid Entry", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Entry in mask is INVALID", "Invalid Entry", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
        End Sub
        Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Me.Close()
        End
    Sub

     Output:-
     
    MaskedTextBox2.gif

    MaskedTextBox3.gifMaskedTextBox4.gif

    MaskedTextBox5.gifMaskedTextBox6.gif
     

Login to add your contents and source code to this article
share this article :
post comment
 

Hi, This is great article !!! really nice stuff, thanks for sharing with us. It's help me lot and this link http://mindstick.com/Articles/8a955dfa-6b51-494d-be88-ec5751963bc0/default.aspx?MaskedTextBox+Control+in+VB.Net also helped me lot. Thanks !!!!!

Posted by Chintoo Khaade Oct 08, 2011
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor