开发者

Pop out menu for any control?

I have a 开发者_运维技巧couple places where a menu would be a better choice than display a dialog box and asked the user a question. Problem is I don't know how to do this.

Here's the scenario:

Current Situation: I have a picture box that is functioning like a button. The user clicks on the box and a dialog box pops up asking them to select a category User selects a category and proceeds to do what they want

Desired Situation I have a picture box that is functioning like a button. The user clicks on the box and a menu slides out where their cursor is listing the categories the user selects a category and proceeds to do what they want OR the user clicks somewhere else and the menu goes away

How can this be done? Is there a built-in way to do it?


A ContextMenuStrip is probably what you want: http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx

ContextMenuStrip replaces ContextMenu. You can associate a ContextMenuStrip with any control, and a right mouse click automatically displays the shortcut menu. You can show a ContextMenuStrip programmatically by using the Show method. ContextMenuStrip supports cancelable Opening and Closing events to handle dynamic population and multiple-click scenarios. ContextMenuStrip supports images, menu-item check state, text, access keys, shortcuts, and cascading menus.

Edit: Bolded the part of the documentation that talks about using the Show() methods to programatically control when the ContextMenuStrip is displayed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜