views:

788

answers:

2

I have a MDI container form, and some child forms that update their title bar texts themselves, independently. After the Text property is changed on the child form, the new title bar text from the child is not updated in the window list menu when the menu is opened. This is the auto-generated window list provided by .NET via the MdiWindowListItem property.

The change only propagates when another event changes the window list physically (opening a new child, closing a child, switching to another child).

Is there a way to force an update of the window list programmatically? I already have some code in place to do menu enabling/disabling at the same time the child's title bar text is changed.

I tried the following with no success:

  • Update() on the main MenuStrip
  • Refresh() on the main MenuStrip
  • Invalidate() on the window MenuStrip
  • Invalidate() on one of the window list items at runtime
  • Toggling the Checked state twice on one of the window list items at runtime

There doesn't seem to be any other remotely viable functions to call on the menu item, its parent ToolStrip, or the parent form that contains the menu system.

+1  A: 

You need to add a TextChanged event to the child form, with this handler:

private void childForm_TextChanged(object sender, EventArgs e) {
    this.ActivateMdiChild( null );
    this.ActivateMdiChild( sender as Form );
}

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/a36b89aa-57aa-48b5-87a6-49fbddc9c92d

MiffTheFox
+3  A: 

The above solution did not work for me. But I followed the link, and found this, which works perfectly:

private void windowMenu_DropDownOpening(object sender, EventArgs e)
{
    if (this.ActiveMdiChild != null)
    {
        Form activeChild = this.ActiveMdiChild;

        ActivateMdiChild(null);
        ActivateMdiChild(activeChild);
    }
}

Thank you!

Jon Seigel