CodeItBetter Programming Another VB Programming Blog

How to Make a TextBox accept only digits using API

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'Controls - How to Make a TextBox accept only digits using API
'Use the SetWindowLong API function to set the TextBox's extended style to
'include ES_NUMBER. Then subclass the control to monitor its messages.

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 As Long = (-16)
Private Const ES_NUMBER As Long = &H2000
 
Private Sub Form_Load()
    Dim style As Long
 
    ' Get the current style.
    style = GetWindowLong(Text1.hwnd, GWL_STYLE)
 
    ' Add ES_NUMBER to the style.
    SetWindowLong Text1.hwnd, GWL_STYLE, style Or ES_NUMBER
End Sub

Related posts:

  1. How to make a TextBox automatically capitalize input using the API
  2. How to lowercase the text entered in text box using API
  3. How to uppercase the text entered in text box using API
  4. How to Make a Text Box Resizeable
  5. How to align Caption on Command Button
  6. How to set Option Button and Check Box Style Property At run time
  7. How to add a minimize Button to Form that has fixed Border
  8. How to disable builtin right click context menu in text box
  9. How to Hide/Show the Title bar at Run-Time
  10. How to select the text in a textbox and send it to the clipoard.

Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.