'_______________________________________________________________________________ ' R K M A S K E D T E X T B O X C U S T O M C O N T R O L ' By Ron Kessler ' Created 12/26/06 '_______________________________________________________________________________ 'This control expands the capability of the MaskedTextBox control to limit input to Telephone, Zip code, ' or Social Security Number. It also can be used to allow all data input as well. 'Be sure to set the default value of the DataType property in the Initialize event which is in the '.Designer.vb file as I show you below: 'Private Sub InitializeComponent() ' components = New System.ComponentModel.Container() ' 'RK_RichTextbox ' m_LegalFormat = FormatOption.All 'this sets the DataType property to "ALL" 'End Sub Public Class RK_MaskedTB Inherits System.Windows.Forms.MaskedTextBox Private m_LegalFormat As FormatOption 'holds the selected datatype Private m_testExpression As String = String.Empty '---define the values for the legal keys in an enumeration _ ' This is like creating a variable but limiting the values to those in my list. Enum FormatOption All TelephoneNumber ZipCode SocialSecurity End Enum Public Property DataType() As FormatOption Get DataType = m_LegalFormat End Get Set(ByVal value As FormatOption) m_LegalFormat = value Select Case m_LegalFormat Case FormatOption.All 'accept all, no test Case FormatOption.TelephoneNumber Me.Mask = "(999) 000-0000" Case FormatOption.ZipCode Me.Mask = "00000-9999" Case FormatOption.SocialSecurity Me.Mask = "000-00-0000" End Select End Set End Property End Class