質問

I have an MDI application. I have a ToolStripMenuItem labeled "Window" that is set as the MdiWindowListItem of my main MenuStrip. The Window menu has a couple of items, such as "Cascade" and "Arrange Icons".

When I run my application, the Window menu ends neatly with my "Arrange Icons" item. As expected, when I open one or more MDI child forms, these are automatically appended after a ToolStripSeparator. When I close all of the child forms, they disappear as expected from the "Window" menu, however the ToolStripSeparator remains. I would have expected the menu to return to its original state, i.e. without the separator.

As it stands, the separator is automatically added but not automatically removed. I could try to programmatically eliminate the extra separator, of course, but I don't see anyone else complaining about this, which leads me to suspect that it might be happening because I did something wrong. Please advise.

役に立ちましたか?

解決

Try adding your own ToolStripSeparator menu item after your "Arrange Icons" menu items and set the Visible property to false.

When opening an MDI child form, make it visible:

  Form f = new Form();
  f.Text = "Test Form";
  f.MdiParent = this;
  f.FormClosed += ChildClosed;
  f.Show();
  ts.Visible = true;

Then in the ChildClosed method:

void ChildClosed(object sender, FormClosedEventArgs e) {
  this.BeginInvoke((Action)delegate 
                      { ts.Visible = (this.MdiChildren.Count() > 0); }
                  );
}

他のヒント

ts.Visible = (this.MdiChildren.Count() > 1)
in the closed event of the child is enough. No need for a BeginInvoke

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top