We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to prevent the form containing the combo from getting deactivated when pressing mouse-down on the drop-down list box

 

This is assuming you are using a list box as your drop-down ListControl:

The reason the combo-containing form gets deactivated is because when you mouse-down on the list box, it activates its parent form (the list box itself will be hosted on a borderless form).

You can work around this by deriving from a list box as follows and using it in place of the list box:

C#

public class StaticListBox : ListBox

{

   protected override void WndProc(ref Message m)

   {

     // Prevent the list box from processing the LeftMouse Down message,

     // since it activates it's parent Form in it's Default Wnd Proc.

     if(m.Msg == 0x201/*WM_LBUTTONDOWN*/)

     {

       return;

     }

   base.WndProc(ref m);

   }

}

 

VB

Public Class StaticListBox Inherits ListBox

   Protected Overrides Sub WndProc(ByRef m As Message)

     ' Prevent the list box from processing the LeftMouse Down message,

     ' since it activates it's parent Form in it's Default Wnd Proc.

     If m.Msg = 0x201 Then

       Return

     End If

     MyBase.WndProc( m)

   End Sub

End Class

Article ID: Published Date: Last Revised Date: Platform: Control:
1082 04/30/2011 07/10/2014 Windows Forms ComboBoxBase
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.