.NET有可能在组合框的项目上有一个上下文菜单吗? [英] .NET Is it possible to have a contextmenu on an item of a combobox?

查看:99
本文介绍了.NET有可能在组合框的项目上有一个上下文菜单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有包含几个项目的下拉列表。我想在用户在下拉项上单击鼠标右键时显示​​上下文菜单。这可能吗?如果可能,如何?

解决方案

因为 MenuItem 没有ContextMenu属性,它不像许多其他控件一样容易。您可能需要捕获右键单击事件,然后手动显示上下文菜单。



有两个警告:





  • 列表失去焦点时,组合框列表将关闭,因此当显示上下文菜单
    时,它可能会关闭
    用户不清楚他们点击了什么
    (不是100%肯定在
    这一点,因为我没有写的
    代码来测试。)

  • $更重要的是,虽然我会认为
    这是一个糟糕的UI选择,I
    不能想到任何真实世界
    应用程序,我使用在菜单项上有
    上下文菜单,因此
    对于
    最终用户来说是不可发现的。加上下文菜单应该
    只是为了快速访问,他们
    不应该是访问
    功能的唯一方法。你会成为
    能通过其他方式暴露这些函数
    以及右键菜单吗?



In my application I have dropdown list with several items. I'd like to show a context menu when the user clicks the right mouse button on a dropdown item. Is this possible? And if it is possible, how?

解决方案

Since MenuItem doesn't have a ContextMenu property it isn't as easy as it is with many other controls. You'll probably need to capture the right-click event and then position and show the context menu manually.

Two caveats though:

  • The combobox list will close when the list loses focus, so it may close when the context menu is shown leaving the user unclear as to what they clicked on (not 100% sure on this, since I haven't written the code to test.)

  • More importantly though I would argue that this is a poor UI choice, I can't think of any real world applications I've used that have context menus on menu items, so it wouldn't be very discoverable for the end user. Plus context menus should be just for quick access, they shouldn't be the only way to access functionality. Are you going to be able to expose these functions through other means as well as the right-click menu?

这篇关于.NET有可能在组合框的项目上有一个上下文菜单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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