Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to remove MenuStrip from MDI child
Message
De
08/01/2007 04:50:40
 
 
À
07/01/2007 18:28:10
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01183318
Message ID:
01183377
Vues:
30
Hi,

Firstly you'll need to set the Visible property of the menustrip in the child form to false - otherwise it will show up even if empty.

But that doesn't address the issue of why the 'File' option is not getting merged. You could try setting the MergeAction to 'MatchOnly' in the parent form as well (I'm not sure about this but although Help states that this is the default a reset sets the MergeAction to 'Append')

HTH,
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();
> }
> }
>}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform