.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to add a ContextMenuStrip to a ToolStripDropDownButton

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application

I have a ToolStrip that has various drop down menus (ToolStripDropDownButtons). Several of these menus are dynamic - the items are added and removed programmatically, depending on actions the user has performed elsewhere (like the MRU files listing at the bottom of a File menu).

I'd like to offer a simple way for a user to remove a menu item from a menu. To do this, I would like to be able to associate a ContextMenuStrip to some of these menus, which would have a "Delete" or "Remove", that, when selected, would remove the menu item.

You can see similar behavior in the Windows Start Menu. If you go to Start/Programs, you can right-click on any menu item and get a context menu to open, delete, or rename the selected menu item.

Unfortunately, ToolStripDropDownButton is not derived from Windows.Forms.Control, so it does not have a ContextMenuStrip property. I attempted to add a ContextMenuStrip to the parent ToolStrip, but it only affects the tool strip and its top-level menu items - right-clicking on submenus does not invoke the context menu.

I've also tried overriding the MouseUp event on individual menu items, handling the right-click and just bringing up the context menu manually, but this results in original menu closing - which isn't very helpful to a user who wants to double-check that he/she is removing the correct menu

View Complete Post

More Related Resource Links

How to show horizontal bar in ToolStripDropDownButton for ToolStripMenuItems

Hi, I am using a ToolStripSplitButton and there are several ToolStripMenuItems. I would like to have the left side bar (like in right click context menus) there. Is it possible to do so? Is there any property to set? Thank you! CJ

Open ContextMenuStrip on left mouse click on NotifyIcon

Hi,I was working with an application and faced this problem, I have this code :public partial class Form2 : Form    {        public Form2()        {            InitializeComponent();        }        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                contextMenuStrip1.Show(this, Control.MousePosition); // Or any other overload            }        }        private void Form2_Load(object sender, EventArgs e)        {            notifyIcon1.Icon = Icon;        }    }Here, in design mode, i have set contextMenuStrip1 as notifyIcon1's ContextMenuStrip. When I right click on notifyIcon1, it opens the context menu and when I click somewhere else, it closes. But with my code opens the contextmenu on left click and when I open context menu that way, it shows in taskbar and doesn't close when I click some where else.In short, I want to open contextmenustrip when user left clicks and right clicks on the notifyicon and it works well with right click by default but not with left click. And I want to avoid using SendMessage to send left click message.Is there any way I can work this out?

Open WinForms ContextMenuStrip in a WPF popup

Hi! I have a very strange problem. I have a WPF popup window which display a listbox. When I right-click the listbox, I want to show a WinForms ContextMenuStrip as a context menu. For historical reasons I can not easily convert this context menu to a WPF ContextMenu. The problem is now, that the ContextMenuStrip opens as expected, however I can not select an element with the mouse. It seems, that the control is disabled. When I close the popup-window everything works fine. Any ideas? Thanks in advance. Jus    

ToolStripDropDown and ContextMenuStrip

I am using the ToolStripDropDown control to host an user control to simulate the pop-up window behavior but encountered the strange problem which I am unable to solve. The ToolStripDropDown control has a ContextMenuStrip attached to it (or some child control does) but when this ContexMenuStrip is shown, the parent ToolStripDropDown pop-up window is closed. When I use the ContextMenu class (which is deprecated and replaced by the ContextMenuStrip) the problem does not occure and the ToolStripDropDown window is not closed.
I thought there is some problem with the WM_ACTIVATE notification and tried to subclass the ContextMenuStrip to force the WS_EX_NOACTIVATE in the CreateParams but no improvement there. I have also tried to manipulate the Closing event but this resulted that the ToolStripDropDown did not closed properly as it already had lost the activation when the ContextMenuStrip was opened.
What is the difference between the ContextMenu and ContextMenuStrip and is there any solution to this problem or any workaround?
Thanks for an answer.

Get ContextMenuStrip at runtime


Hii All,

I use VB.NET 2005 and I have the next problem:

I want to get the ContextMenuStrip controls that exist in a Form at the runtime. When I used the  

Form.Controls collection I didn't find any ContextMenuStrip inside it and I found it inside "components"

collection, but components access modifier is "Private" and I want to access components from other class

and I don't want to change its access modifer.

I hope you got my problem and wait for help.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend