本文介绍了如何组合框,表格上显示列表项,拦截鼠标事件时,无处可藏的名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个.NET窗体控件类似于组合框的功能,但我不知道正确的方法在任何地方拦截鼠标事件的形式,对未展开的项目列表。

I'm trying to implement a .net form control with functionality similar to a combo box, but I don't know the proper method to intercept mouse events anywhere on the form to un-expand the list of items.

我如何起价响应鼠标事件,而列表中正在显示p $ pvent其他控制?

How do I prevent other controls from responding to mouse events while the list is being shown?

我如何高效,安全地搭上了鼠标点击事件的任何地方的形式,隐藏展开的列表?

How do I efficiently and safely catch a mouse click event to anywhere on the form, to hide the expanded list?

推荐答案

只需使用 ToolStripControlHost 随着 ToolStripDropDown ,和它的工作就像组合框下拉。你会不会担心处理的鼠标事件。

Just use a ToolStripControlHost along with the ToolStripDropDown, and it will work just like the ComboBox dropdown. You won't have to worry about handling the mouse events.

我以前用过这样的:

Private Sub ShowControl(ByVal fromControl As Control, ByVal whichControl As Control)
  '\\ whichControl needs MinimumSize set:'
  whichControl.MinimumSize = whichControl.Size

  Dim toolDrop As New ToolStripDropDown()
  Dim toolHost As New ToolStripControlHost(whichControl)
  toolHost.Margin = New Padding(0)
  toolDrop.Padding = New Padding(0)
  toolDrop.Items.Add(toolHost)
  toolDrop.Show(Me, New Point(fromControl.Left, fromControl.Bottom))
End Sub

快速演示与窗体上的一个按钮控件:

Quick Demo with a Button control on a form:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  ShowControl(Button1, New MonthCalendar)
End Sub

要回答你的标题问题,我的认为的的的的PInvoke的和的用于处理这种类型的功能释放捕获。

To answer the question in your title, I think the pinvoke calls of SetCapture and Release Capture are used to handle that type of functionality.

这篇关于如何组合框,表格上显示列表项,拦截鼠标事件时,无处可藏的名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:48