The text box adds a Validtext property to get and set valid text input by inheriting the textbox
There is also a editable property that determines whether the text box supports backspace editing.
I am just learning vb.net, hope to communicate with you, I have to qq:36745349
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox
Private M_strvalidtext as String = "0123456789.+-" & Chr (13). Tostring
Private m_blneditable as Boolean = True
#Region "code generated by the Windows forms Designer"
Public Sub New ()
MyBase.New ()
' This call is required by the Windows Forms Designer.
InitializeComponent ()
' Add any initialization after the InitializeComponent () call
End Sub
' UserControl1 overrides dispose to clean up the list of components.
Protected Overloads Overrides Sub Dispose (ByVal disposing as Boolean)
If disposing Then
If not (components are nothing) Then
Components. Dispose ()
End If
End If
Mybase.dispose (disposing)
End Sub
' Required by the Windows Forms Designer
Private Components as System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Forms Designer
' You can use the Windows Forms Designer to modify this procedure.
' Do not modify it using the Code Editor.
<system.diagnostics.debuggerstepthrough () > Private Sub InitializeComponent ()
components = New System.ComponentModel.Container
End Sub
#End Region
Private Sub mytextbox_keypress (ByVal sender as Object, ByVal e as System.Windows.Forms.KeyPressEventArgs) Handles MyBase. KeyPress
Dim strlocalstring as String
If EditAble Then
strlocalstring = M_strvalidtext & Chr (8). Tostring
Else
strlocalstring = M_strvalidtext
End If
If UCase (strlocalstring). IndexOf (UCase (E.keychar)) < 0 Then
e.handled = True
Beep ()
Else
End If
End Sub
Public Property Validtext () as String
Get
Return M_strvalidtext
End Get
Set (ByVal Value as String)
M_strvalidtext = Value
End Set
End Property
Public Property EditAble () as Boolean
Get
Return m_blneditable
End Get
Set (ByVal Value as Boolean)
M_blneditable = Value
End Set
End Property
End Class
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service