How does a ComboBox capture mouse when it is dropped-down?

后端 未结 2 388
闹比i
闹比i 2021-01-12 09:50

I am trying to model the behavior of a ComboBox dropdown (or other drop downs for that matter, including context menus) where the drop down closes when you click anywhere el

相关标签:
2条回答
  • 2021-01-12 10:39

    The templates of the controls you've mentioned are using for the dropdown lists a popup as a container with the StaysOpen property set on false (which is the default i think).

    ComboBox template example

    0 讨论(0)
  • 2021-01-12 10:40

    The ComboBox is constructed from 2 controls.

    • Base - visible when not active (Control)
    • DropDownList - visible during edit mode or list selection mode (Window or Form)

    Normally the Base is visible. When the user clicks onto the ComboBox, the Base control hides and the DropDownList control shows up. This switch is done on the background, so for the user it seems the control just expanded.

    The event you want to catch is done through the DropDownList Window. If you click somewhere onto your client area, the DropDownList Window receives the WM_KILLFOCUS event through it's WndProc(Message% m) method. Then sends to the parent window (the Base control) a WM_COMMAND (OCM_COMMAND) message with WParam=526318 (HIWORD(WParam)=8) and the Base control knows he should hide the DropDownList Window.

    So, what you need to do is implement the additional DropDown Window and catch the WM_KILLFOCUS event.

    0 讨论(0)
提交回复
热议问题