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


Post New Web Links

ToolStripDropDown and ContextMenuStrip

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :Windows Application
 
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.


View Complete Post


More Related Resource Links

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    

How to remove the space for image in Toolstripdropdown

  

Hi! Everyone,

I have added a Toolstripcontrolhost with a own usercontrol to a Toolstripsplitbutton.dropdownItems. But there is always the space on the right and left side beside the toolstripcontrolhost. Has somebody any idea about how can i remove them?

I have set the margin and padding of the Toolstripsplitbutton.dropdownItems[index] to 0. But it doesn't help anything. I have also check other threads in this forum about the similar problem with contextmenu. But there is not such property like ShowShortCutKeys = false;
ShowCheckMargin = false;
ShowImageMargin = false; for Toolstripsplitbutton.dropdownItems[index] or for Toolstripsplitbutton.dropdown. Does somebody ever has that problem before?


why is there empty space between a instance of Toolstripcontrolhost and Toolstripdropdown

  

Hi Everybody!

I have following problem. I add a Usercontrol usercontrol to a Toolstripcontrolhost host, and then add host to Toolstripdropdown.items dropdown. At every opening of the dropdown I will update the usercontrol. After update the usercontrol a empty space between top of the dropdown and the content appears. Does somebody know why, and how I can solve it?


How to remove the space for image in Toolstripdropdown

  

Hi! Everyone,

I have added a Toolstripcontrolhost with a own usercontrol to a Toolstripsplitbutton.dropdownItems. But there is always the space on the right and left side beside the toolstripcontrolhost. Has somebody any idea about how can i remove them?

I have set the margin and padding of the Toolstripsplitbutton.dropdownItems[index] to 0. But it doesn't help anything. I have also check other threads in this forum about the similar problem with contextmenu. But there is not such property like ShowShortCutKeys = false;
ShowCheckMargin = false;
ShowImageMargin = false; for Toolstripsplitbutton.dropdownItems[index] or for Toolstripsplitbutton.dropdown. Does somebody ever has that problem before?


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.



How to add a ContextMenuStrip to a ToolStripDropDownButton

  

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

Categories: 
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