Differences between .ContextMenu and .ContextMenuStrip

柔情痞子 提交于 2020-01-01 00:58:13

问题


What are the differences between .ContextMenu and .ContextMenuStrip in Windows Forms?

I already know what a ContextMenu is, but how is ContextMenuStrip different from ContextMenu?


回答1:


http://www.informit.com/articles/article.aspx?p=606224&seqNum=2

You might wonder why Microsoft has replaced a valuable and popular control with a newcomer. The ContextMenuStrip control takes a good idea and makes it better. It works just like the ContextMenu control. You still attach a ContextMenuStrip control to another user control by changing that control’s ContextMenuStrip property. However, Microsoft has substantially improved the features you can add to a ContextMenuStrip cont...

Look at the examples at MSDN:

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.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.contextmenustrip.aspx

If a ContextMenu has also been assigned to the control, the ContextMenu takes precedence over the ContextMenuStrip.




回答2:


From the doc

ContextMenuStrip replaces ContextMenu.




回答3:


According to the MSDN, the ContextMenuStrip replaces the ContextMenu class:

Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if you choose.

Source: MSDN - ContextMenu

Edit: why the -1?




回答4:


contextMenu - msdn and contextMenuStrip - msdn

contextMenu - Represents a shortcut menu. Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if you choose.

ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions




回答5:


If you hoover over ContextMenu you'll notice that ContextMenuStrip replaces it but ContextMenu has been left for compatibility purposes.



来源:https://stackoverflow.com/questions/8442292/differences-between-contextmenu-and-contextmenustrip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!