Winforms: how to open combobox properly?

后端 未结 5 1025
醉梦人生
醉梦人生 2020-12-06 16:26

I have a combobox on the winforms. On Enter even I open it:

cbo.DroppedDown = true;

But if I do that the combo opens and closes immediately

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 16:43

    The reason you are having this problem is because the mouseup event occurs after the enter event and the default window procedure is closing the combobox.

    In the enter you could check the mouse button status and if the button is down, do not open the combo. Then have another event handler for the mouseup event to open the combo.

    Another option is to set a timer for a few milliseconds, and open the combo when it goes off.

提交回复
热议问题