.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Masked TextBox in VB.Net for Windows App

Posted By:Narayanan       Posted Date: April 02, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

Masked TextBox: A Masked Textbox control provides validation mechanism for user input on a Form. By default masked property is set to none and the control works like a normal TextBox control.

How to use Masked TextBox Control for Short Date


·         Drag and drop MaskedTextBox and Button (change its Text to Test) control from toolbox on the window Form.

·         Set ShortDate Mask for MaskedTextBox using SetMask Property.


 Validate MaskedTextBox for short Date:


Code in VB.net


Copy and Paste this Code in your form or Module:

Private Sub CheckDateFormatforMaskedTextBox(ByVal maskedText As MaskedTextBox)

        Dim dtp As DateTime

        Dim result As Boolean

        result = DateTime.TryParseExact(Me.MaskedTextBox1.Text, "dd/MM/yyyy", Nothing, System.Globalization.DateTimeStyles.None, [dtp]).ToString()

        If result = False Then

            MessageBox.Show("Please Check your Input")

        End If

    End Sub



Call this function in your MaskedTextBox Leave Event:


CheckDateFormatforMaskedTextBox(<Your MaskedTextBox Name>)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend