In some applications, the kind of a multiple-document interface (MDI) child window can be different from the MDI parent window. For example, the MDI parent might be a spreadsheet, and the MDI child might be a chart. In that case, you want to update the contents of the MDI parent's menu with the contents of the MDI child's menu as MDI child windows of different kinds are activated.
The following procedure uses the IsMdiContainer, AllowMerge, MergeAction, and MergeIndex properties to remove a menu item from the drop-down part of the MDI parent menu. Closing the MDI child window restores the removed menu items to the MDI parent menu.
To remove a MenuStrip from an MDI drop-down menu
Create a form and set its IsMdiContainer property to true.
Within the event handler, insert code similar to the following code example to create and display new instances of Form2 as MDI children of Form1:
Private Sub openToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openToolStripMenuItem.Click
Dim NewMDIChild As New Form2()
'Set the parent form of the child window.
NewMDIChild.MdiParent = Me
'Display the new form.
NewMDIChild.Show()
End Sub
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 newMDIChild = new Form2();
// Set the parent form of the child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
Place code similar to the following code example in the &OpenToolStripMenuItem to register the event handler.
Private Sub openToolStripMenuItem_Click(sender As Object, e As _
EventArgs) Handles openToolStripMenuItem.Click
this.openToolStripMenuItem.Click += new _
System.EventHandler(this.openToolStripMenuItem_Click);
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Desktop feedback
feedback
.NET Desktop feedback
is an open source project. Select a link to provide feedback: