让TextBox只允许输入数字

Visual Basic Code
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA"   ( ByVal hwnd As Long, ByVal nIndex As Long )   As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA"   ( ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long )   As Long
Private Const GWL_STYLE As Long   =   -16
Private Const ES_NUMBER As Long   =   &H2000

Private Sub Form_Load (   )  
        Dim lOldStytle As Long
        Dim ret As Long

        lOldStytle   =   GetWindowLong ( Text1.hwnd, GWL_STYLE )  
        lOldStytle   =   lOldStytle Or ES_NUMBER
        ret   =   SetWindowLong ( Text1.hwnd, GWL_STYLE, lOldStytle )  
End Sub

你可能感兴趣的:(让TextBox只允许输入数字)