Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

21. Windows Forms ComboBox

21.2 How can I programmatically prevent the combobox from dropping?


You can avoid the combobox dropping by overriding its WndProc method and ignoring the WM_LBUTTONDOWN and WM_LBUTTONDBLCLK.

[C#]
public class MyComboBox : ComboBox
{
     protected override void WndProc(ref System.Windows.Forms.Message m)
     {
           if(m.Msg == 0x201 //WM_LBUTTONDOWN
           || m.Msg == 0x203) //WM_LBUTTONDBLCLK
                return;
          base.WndProc(ref m);
     }
}

[VB.NET]
Public Class MyComboBox
     Inherits ComboBox

     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
          If m.Msg = &H201 OrElse m.Msg = &H203 Then 'WM_LBUTTONDOWN or WM_LBUTTONDBLCLK
               Return
          End If

          MyBase.WndProc(m)
     End Sub 'WndProc
End Class 'MyComboBox