VB Text Control Application

zhaozj2021-02-16  48

TextBox control:

a. Control the TextBox input format, I think most people encounter this problem, when TextBox is used as an input interface, sometimes we want users to enter digital, uppercase, letters, etc., the general approach is the character to check the user input. But if we use the API, it will be easily implemented, such as:

1, only allow input numbers:

Const ES_NUMBER = & H2000 Public Function NumBersonly (TBOX As Textbox)

DIM DefaultStyle As Long

DefaultStyle = getWindowlong (TBOX.HWND, GWL_STYLE)

NumBersonly = setWindowlong (TBOX.HWND, GWL_STYLE, DEFAULTSTYLE OR ES_NUMBER)

END FUNCTION

2, only allowance:

Public Function UppercaseOnly (TBOX As Textbox)

DIM DefaultStyle As Long

DefaultStyle = getWindowlong (TBOX.HWND, GWL_STYLE)

Uppercaseonly = setWindowlong (TBOX.HWND, GWL_STYLE, DefaultStyle or ES_UPPPERCASE)

END FUNCTION

3, only allow lowercase:

Public Function LowerCaseOnly (TBOX As Textbox)

DIM DefaultStyle As Long

DefaultStyle = getWindowlong (TBOX.HWND, GWL_STYLE)

LowerCaseOnly = setWindowlong (tbox.hwnd, gwl_style, defaultstyle or es_lowercase)

END FUNCTION

Of course, three functions on the upper side can be synthesized because they are the same, but style parameters are different.

转载请注明原文地址:https://www.9cbs.com/read-19925.html

New Post(0)