改变TextBox的风格,只能输入数字/大写/小写

引用内容 引用内容

Option Explicit
DefInt A-Z
'DefInt (字母范围) 定义整型 -> 所有以A-Z字母开头的都是整型变量

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function
GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Const
GWL_STYLE = -16

Enum TxtBoxStyles
    ES_UPPERCASE =
&H8&        
'大写
    
ES_LOWERCASE = &H10&    '小写
    
ES_NUMBER = &H2000&        '数字
End Enum

Public Sub
SetTxtBoxStyle(hWnd As Long, InputStyle As TxtBoxStyles)
    
Dim lngStyle As Long
    
lngStyle = GetWindowLong(hWnd, GWL_STYLE)
    lngStyle = lngStyle
Or InputStyle
    SetWindowLong hWnd, GWL_STYLE, Style
End Sub



文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: VB
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.