Limit Users Typing in Combo Box

Limit Users Typing in Combo Box

The standard textbox has a MaxChars property that lets you limit the number of characters a user can type into it. The drop-down combo does not, but you can emulate this property setting with a simple API call:

 Private Declare Function SendMessage Lib _"user32" Alias "SendMessageA" (ByVal hWnd _As Long, ByVal msg As Long, ByVal wParam _As Long, ByVal lParam As Long) As LongPrivate Const CB_LIMITTEXT = &H141Private Sub Form_Load()Const Max_Char = 24Call SendMessage(Combo1.hWnd, _CB_LIMITTEXT, Max_Char, 0&)End Sub

This tip works in 16-bit versions of VB as well, but you


Share the Post: