My setup is very simple.
I have a form called FormBaseList, on that form there is a DataGridView and a ContextMenuStrip. The ContextMenuStrip is coupled to the DataGridView and has 2 menuitems.
Now I add a new form to my project, using add Windows Form and then I choose "Windows Forms" / "Inherited Form". As base I choose my FormBaseList.
So now I have a new form, called FormSomethingList that is derived from FormBaseList.
In the visual designer I can now add an additional MenuItem to the ContextMenuStrip on FormSomethingList, but if I compile and run the application, that new MenuItem is gone. When I open FormSomeThingList in the designer the new MenuItem is also gone...
Is this "normal" behaviour or is there something wrong with my project ? I suspect the first but would like some confirmation. And if this is indeed "normal" behaviour, how can I workaround it without doing it all in code.
You don't even have to run the application. If you just rebuild, you will see that the menu option is gone. With each build, you are telling Form2 that it is a form 1, and the context menu gets set to what that is. In fact, notice that in form 2, the properties for the context menu are not editable. Unfortunately, the GUI allows you to type in additional values for the context menu, but if you try to change this by changing the "Items" collection property, in the property window, you will not be able to.
You will just need to add the item programatically. But that is not such a big deal. When you added the menu item in form 2, after you rebuilt, it disappeared from the context menu, but it is still there. Look in the designer code and you will see it. The menu item is still defined as part of form 2, but it's just been disconnected from the context menu. So on form2's load event, you can just readd it.
contextMenuStrip1.Items.Add(myAddedMenuStripItem);
Look in the designer.cs to see the name of the item you added to the context menu.
Related
I all of a sudden can get my ContextMenuStrip to work on the form window itself. If i right click on my label or on my notify icon it works but nothing happens on the form itself. I'm certain it worked before I renamed the form but I can't seem to find out where the problem could stem from.
The ContextMenuStrip is correctly and identically set on both the form as well as the label and notify icon.
Anybody know where there problem could be? If my code is needed I will add it.
Check forms ContextMenuStrip property is properly set.
My goal is to emulate the Smart tag already on the menustrip in visual studio that inserts the common menu items.
I'd like to have the user be able to select the item they want from a drop down (I have that already using a UITypeEditor) and then have the items created just like they normally would be at design time (part of the form's components with their creation code in the .Designer.cs file).
The best I have been able to do is to have the menustrip control create the items and add them to it's Items collection. The problem is that the items can't be manipulated further at design time. The menu containing them is actually 'locked'. For the user to add more buttons they would have to do it dynamically at run time.
Is my goal possible and if so could some one point me in the right direction?
I'm not positive, but I think you need to interact with the IComponentChangedService and inform it that your menu has changed. It's been a while since I've written design time support for controls.
In your designer:
IComponentChangeService changeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
Actually
I think it is the DesignHost you need check out this:
IDesignerHost designHost = (IDesignerHost)GetService(typeof(IDesignerHost));
designHost.Container.Add(...)
I believe you have to add your component to it to manage it.
How can I add an item to a contextmenustrip, as well as code the button_click action for it?
I'm making a web browser application, and I have a drop down menu of 'favorite' websites. When someone clicks a button, it adds the title of the website into the dropdown menu, but I also need it navigable to the website URL that was inputted. I have no idea how to add button click actions when I add a new item to a contextmenustrip.
Is this a WinForms application?
If so, in the Visual Studio designer, after you drag a contextMenuStrip from the boolbox, it allows you to type new entries at the contextMenuStrip (click where it says 'Type Here' to add a new item). If you are going back to an existing contextMenuStrip, you will have to make it appear by clicking on the contextMenuStrip item at the bottom of the designer.
Once you have the item, you can just double-click on it to whatever code you want to execute on the click event. (This is the default event; for other events you will have to double-click the appropriate event from the Properties pane.
How can I merge menu items of parent form and child form with same menu name?
Set the MergeAction of the menu items to "MatchOnly".
Added
Because this can get a little tricky, I'll add a list of steps to make a simple example.
Create a new Windows Forms Application.
Add a new Windows Form and leave its name Form2.
Open Form1 designer (if not already open).
Click on the form and set Form1's IsMdiContainer to True.
Open the toolbox and add a MenuStrip to Form1.
In the "Type Here" box type &File
In the sub-item "Type Here" box type A
In the sub-item "Type Here" box type B
Your MDI container (Form1) should
have a File menu with items A and B.
Double-click the A item to add a
click handler.
Add new Form2 { MdiParent = this }.Show(); to the handler method.
Open Form2 designer.
Open the toolbox and add a MenuStrip
to Form2.
Note: See below for information about the Visible property on the Form2 MenuStrip, which could be set to False at this point.
In the "Type Here" box type &File
In the sub-item "Type Here" box type
C
Your MDI child (Form2) should have a
File menu with item C.
Click on the File menu item and in
the Properties window set MergeAction
to MatchOnly.
Run the program.
Notice that the File menu items are A and B.
Click File -> A to create a child window.
Notice that the File menu on the container now contains A, B, and C.
Notice also that the File menu on the child is there, but has no items. This is because C was merged.
You can now set the child's MenuStrip.Visible property to False so that the child does not display a menu. It is handy to leave this as True when designing your menus so that you can verify that all the child menu items have been merged correctly (they will be gone from the child menu).
You can use the MergeIndex property to control how child items get merged into the container.
We have a composite application with a DockPanelWorkspace as its main user interface area. Above this sits a MenuStrip with a window menu set as its MdiWindowListItem. Unfortunately, as I feared, the window menu isn't populated with the open views.
Is there an equivalent in CAB that will populate a menu with a list of the open views in a workspace? If not, how should I go about implementing that feature?
MdiWindowListItem is automatically populated with items added as MdiChild. You have to develop custom logic for docked window, handling the following .
Adding menu item to the window menu (set as MdiWindowListItem)
Removing the menu item when the related window is closed
EventHandler for selecting the window when the menu is clicked
I am not familiar with DockPanelWorkspace.
So logic of selecting the window has to be sorted.
Changes of DockState like the window changes to MDIChild