.NET Is it possible to have a contextmenu on an item of a combobox?

后端 未结 6 1636
迷失自我
迷失自我 2021-01-20 04:42

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?

6条回答
  •  独厮守ぢ
    2021-01-20 05:20

    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?

提交回复
热议问题