如何做一个组合框捕获鼠标,当它掉落下来? [英] How does a ComboBox capture mouse when it is dropped-down?

查看:229
本文介绍了如何做一个组合框捕获鼠标,当它掉落下来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图模拟一个组合框下拉列表的行为(或其他下拉菜单对于这个问题,包括上下文菜单),其中,当你点击任何地方,甚至在一些不能集中下拉关闭。

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 else, even on something that can't be focused.

我试过认购,如MouseCaptureChanged,引发LostFocus事件,然后离开。我有一个自定义用户控件是作为一个下拉列表,我只是想关闭它,当用户点击其他地方。

I've tried subscribing for events such as MouseCaptureChanged, LostFocus, and Leave. I have a custom UserControl which is acting as a dropdown and I just want to close it up when the user clicks anywhere else.

这看起来像是这样做了很多的控制,所以如果没有一个简单的方法来做到这一点我会感到惊讶。

This seems like something that's done in many controls so I'd be surprised if there wasn't a simple way to do it.

到目前为止,过于复杂的方法,我能想出这个正在使用的PInvoke和SetCapture()函数,或者创建一个MessageFilter的做。如果这是唯一的选择,我不知道哪个好。

So far the overcomplicated methods I can come up with to do this are using pinvoke and the SetCapture() function, or to create a MessageFilter. If these are the only options I am not sure which is better.

推荐答案

组合框是由2控制构造。

The ComboBox is constructed from 2 controls.

  • 在基地 - 可见,当未激活(控制)
  • 的DropDownList - 在编辑模式或选择模式(窗口或表)可见

通常情况下,基本是可见的。当用户点击到组合框,基本控制皮和DropDownList控件显示出来。此开关做的背景,因此对于用户来说似乎只是扩大了控制。

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.

你想赶上这次活动是通过DropDownList的窗口中完成。如果你点击到你的客户区的地方,将DropDownList窗口收到 WM_KILLFOCUS 通过它的事件是的WndProc(消息%M)的方法。然后发送到父窗口(基本控制),一个 WM_COMMAND OCM_COMMAND )消息 wParam参数= 526318 HIWORD(wParam参数) = 8 )和相应的控制知道他应隐藏DropDownList的窗口。

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.

所以,你需要做的是执行额外的下拉窗口和捕捉WM_KILLFOCUS事件。

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

这篇关于如何做一个组合框捕获鼠标,当它掉落下来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆