65.9K
CodeProject 正在变化。 阅读更多。
Home

UserControl 文本框

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (2投票s)

2008年1月29日

CPOL
viewsIcon

30622

downloadIcon

89

仅用于数字、仅字母、字母数字的 Windows 文本框用户控件

引言

这是一个可重用的自定义文本框控件,它允许您仅输入数字、仅输入字母和字母数字值。

背景

Public Class MyTextbox
    Enum opts
        numeric = 0
        charectors = 1
        both = 2
    End Enum
    Dim opt1 As opts
    Public Property options() As opts
        Get
            Return opt1
        End Get
        Set(ByVal value As opts)
            opt1 = value
        End Set
    End Property
    Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Select Case opt1
            Case opts.numeric
                If Char.IsDigit(e.KeyChar) = False Then
                    e.Handled = True
                End If
            Case opts.charectors
                If Char.IsLetter(e.KeyChar) = False Then
                    e.Handled = True
                End If
            Case opts.both
                If Char.IsLetterOrDigit(e.KeyChar) = False Then
                    e.Handled = True
                End If

        End Select
    End Sub
End Class
		

关注点

.Net Windows Forms 文本框用户自定义控件

关于作者

姓名:M.NareshKumar
职业:高级软件工程师
公司:Atherstone Consulting Limited.
地点:印度海得拉巴

© . All rights reserved.