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.
Related
In a user control of mine I implement a tab control that should programmatically manage tab pages. I connected the tab control with a context menu strip with the menu items "Add", "Edit", "Delete" to respectively add a new tab page, edit or delete an existing one. Initially, the tab control does not have any tab pages, and in this case the context menu strip does not appear on right mouse click; if a tab page is there, the context menu strip works as required. At that, the context menu strip is attached to the tab control itself, not to any of the tab pages.
I find this state quite illogical, and my question is whether there is any possibility to make the context menu work attached to a tab control work even if the tab control is empty?
Empty TabControl does not receive mouse events. They are passed to the underlying control.
You can do the following.
Put the TabControl inside a Panel of the same size. Assign the same context menu to this Panel. Then, when TabControl is empty, mouse events will be passed to the Panel and menu will be shown too.
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.
I have a windows form in C# project that keeps Student Info. I caught the image:
I want to add data with sequential order as follows but when I enter data to Surname textbox, TAB button jumps to E-Mail textbox, then Phone Number textbox and lastly to Date of Birth DateTimePicker.
I made all control's TabStop property "False" on the form except these textboxes. And I arranged their TabOrder via Properties Section as follows 0,1,2.. as I intented. But the order followed as I wrote above. Then I opened Tab Order function via "View" on menu strip.. I clicked all controls which I wanted to use in order, but no use. The form and Tab button act as before. I caught Tab Order function image below:
What shall I do now?
TabIndex is important for controls which are siblings of the same parent. However, if your TextBox and ComboBox controls are each inside different parents then their parent controls must have the proper TabIndex.
In the Windows Forms Designer you can see which controls are children of which panels by bringing up the Document Outline. Go to View -> Other Windows -> Document Outline.
If each TextBox or ComboBox is directly inside a parent then its TabIndex doesn't matter, it can be 0. It's the parent (and possibly the parent's parent's) TabIndex which needs to be in order.
Now that we have VS 2019. Simply go to form.cs[design], click "View" tab at the top of the page and select "Tab Order". This will allow you to click on the form elements in order of which you want them to be tabbed to. Any items not selected will not be tabbable(I think I made this word up). Once complete, click "Tab Order" again to exit view.
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.
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