Enabling a Password Char for a ComboBox Control
Comboboxes with DropDownStyle
set to DropDown
do not support a password char for the edit part in Windows Forms of .NET Framework 1.1. SetComboBoxPasswordChar
provides a method to set a combobox’s password char:
Private Declare Auto Function GetWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wCmd As Int32 _
) As IntPtr
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr _
) As IntPtr
Private Const EM_SETPASSWORDCHAR As Int32 = &HCC
Private Const GW_CHILD As Int32 = 5
Private Sub SetComboBoxPasswordChar( _
ByVal ComboBox As ComboBox, _
ByVal PasswordChar As Char _
)
SendMessage( _
GetWindow( _
ComboBox.Handle, _
GW_CHILD _
), _
EM_SETPASSWORDCHAR, _
New IntPtr(AscW(PasswordChar)), _
IntPtr.Zero _
)
ComboBox.Refresh()
End Sub
Usage:
SetComboBoxPasswordChar(Me.ComboBox1, "*"c)