Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to remove MenuStrip from MDI child
Message
From
08/01/2007 06:32:23
 
 
To
07/01/2007 18:28:10
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01183318
Message ID:
01183381
Views:
15
Hi,

Ignore the second part of my first message. A successful MergeAction doesn't remove a menuitem from the source menustrip anyway...

Regards,
Viv


>I found issue in .NET 2 where MenuStrip is not removed from MDI child window.
>
>How to fix this ?
>
>To reproduce:
>
>1. Run the code
>2. Select File / open
>
>Observed: child window contains MenuStrip with File menu item.
>
>Expected: child window should not contain MenuStrip
>
>Code to reproduce the issue:
>
>---- program.cs:
>
>using System.Windows.Forms;
>using WindowsApplication1;
> static class Program {
> static void Main() {
> Application.Run(new Form1());
> }
> }
>
>--- form1.cs
>
>using System.Windows.Forms;
>using System;
>
>namespace WindowsApplication1 {
> public partial class Form1 : Form {
> public Form1() {
> InitializeComponent();
> }
>
> private void openToolStripMenuItem_Click(object sender, EventArgs e) {
> Form2 newMDIChild = new Form2();
> newMDIChild.MdiParent = this;
> newMDIChild.Show();
>
> }
> }
>}
>
>----- form1.designer.cs
>
>namespace WindowsApplication1 {
> partial class Form1 {
> private System.ComponentModel.IContainer components = null;
> protected override void Dispose(bool disposing) {
> if (disposing && (components != null)) {
> components.Dispose();
> }
> base.Dispose(disposing);
> }
>
> #region Windows Form Designer generated code
> private void InitializeComponent() {
> this.menuStrip1 = new System.Windows.Forms.MenuStrip();
> this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
> this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
> this.menuStrip1.SuspendLayout();
> this.SuspendLayout();
> this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
> this.fileToolStripMenuItem});
> this.menuStrip1.Location = new System.Drawing.Point(0, 0);
> this.menuStrip1.Name = "menuStrip1";
> this.menuStrip1.Size = new System.Drawing.Size(292, 24);
> this.menuStrip1.TabIndex = 1;
> this.menuStrip1.Text = "menuStrip1";
> //
> // fileToolStripMenuItem
> //
> this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
> this.openToolStripMenuItem});
> this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
> this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
> this.fileToolStripMenuItem.Text = "&File";
> //
> // openToolStripMenuItem
> //
> this.openToolStripMenuItem.Name = "openToolStripMenuItem";
> this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
> this.openToolStripMenuItem.Text = "&open";
> this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
> //
> // Form1
> //
> this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
> this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
> this.ClientSize = new System.Drawing.Size(292, 273);
> this.Controls.Add(this.menuStrip1);
> this.IsMdiContainer = true;
> this.MainMenuStrip = this.menuStrip1;
> this.Name = "Form1";
> this.Text = "Form1";
> this.menuStrip1.ResumeLayout(false);
> this.menuStrip1.PerformLayout();
> this.ResumeLayout(false);
> this.PerformLayout();
>
> }
>
> #endregion
>
> private System.Windows.Forms.MenuStrip menuStrip1;
> private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
> private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
> }
>}
>
>-------- form2.designer.cs
>
>namespace WindowsApplication1 {
> partial class Form2 {
> private System.ComponentModel.IContainer components = null;
> protected override void Dispose(bool disposing) {
> if (disposing && (components != null)) {
> components.Dispose();
> }
> base.Dispose(disposing);
> }
>
> #region Windows Form Designer generated code
>
> private void InitializeComponent() {
> this.menuStrip1 = new System.Windows.Forms.MenuStrip();
> this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
> this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
> this.menuStrip1.SuspendLayout();
> this.SuspendLayout();
> //
> // menuStrip1
> //
> this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
> this.fileToolStripMenuItem});
> this.menuStrip1.Location = new System.Drawing.Point(0, 0);
> this.menuStrip1.Name = "menuStrip1";
> this.menuStrip1.Size = new System.Drawing.Size(292, 24);
> this.menuStrip1.TabIndex = 0;
> this.menuStrip1.Text = "menuStrip1";
> //
> // fileToolStripMenuItem
> //
> this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
> this.saveToolStripMenuItem});
> this.fileToolStripMenuItem.MergeAction = System.Windows.Forms.MergeAction.MatchOnly;
> this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
> this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
> this.fileToolStripMenuItem.Text = "&File";
> //
> // saveToolStripMenuItem
> //
> this.saveToolStripMenuItem.MergeAction = System.Windows.Forms.MergeAction.Insert;
> this.saveToolStripMenuItem.MergeIndex = 3;
> this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
> this.saveToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
> this.saveToolStripMenuItem.Text = "Save";
> //
> // Form2
> //
> this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
> this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
> this.ClientSize = new System.Drawing.Size(292, 273);
> this.Controls.Add(this.menuStrip1);
> this.MainMenuStrip = this.menuStrip1;
> this.Name = "Form2";
> this.Text = "Form2";
> this.menuStrip1.ResumeLayout(false);
> this.menuStrip1.PerformLayout();
> this.ResumeLayout(false);
> this.PerformLayout();
>
> }
>
> #endregion
>
> private System.Windows.Forms.MenuStrip menuStrip1;
> private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
> private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
> }
>}
>
>
>-------- form2.cs
>
>using System.Windows.Forms;
>
>namespace WindowsApplication1 {
> public partial class Form2 : Form {
> public Form2() {
> InitializeComponent();
> }
> }
>}
Previous
Reply
Map
View

Click here to load this message in the networking platform