Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I programmatically prevent the ComboBox drop-down list from dropping down?

You can prevent the ComboBox dropping by overriding its WndProc method and ignoring the WM_LBUTTONDOWN and WM_LBUTTONDBLCLK.

[C#]

using System.Windows.Forms;

public class CustomComboBox : ComboBox
{
  protected override void WndProc( ref  Message m )
  {
    if ( m.Msg == 0x201 || // WM_LBUTTONDOWN
    m.Msg == 0x203 ) // WM_LBUTTONDBLCLK
    return;
    base.WndProc( ref m );
  }
}

[Visual Basic]

Public Class CustomComboBox
    Inherits ComboBox
  Protected Overrides Sub WndProc(ByRef m As Message)
    'WM_LBUTTONDOWN or WM_LBUTTONDBLCLK
    If m.Msg = &H201 OrElse m.Msg = &H203 Then
      Return
    End If
    MyBase.WndProc(m)
  End Sub
End Class

Contributed from George Shepherd's Windows Forms FAQ



Page view counter