开发者

prevent dropdown area from opening of combobox control in windows forms

开发者 https://www.devze.com 2023-02-17 04:46 出处:网络
I have a custom combo box control in windows forms. I want to achieve a functionality wherein based on some condition the dropdown area should not be displayed i.e. I need to prevent the c开发者_Go百科

I have a custom combo box control in windows forms. I want to achieve a functionality wherein based on some condition the dropdown area should not be displayed i.e. I need to prevent the c开发者_Go百科ombo box from opening based on some condition.

I found a link where this can be achieved but it is completely preventing the dropdown area from showing. Also i am not able to tweak the method as per my convinience. The link is given here.


Just add your condition to that if statement:

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

精彩评论

暂无评论...
验证码 换一张
取 消