MDI window list not updating child title bar texts

▼魔方 西西 提交于 2019-12-21 20:44:24

问题


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 don'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:


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!




回答2:


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




回答3:


Instead of activate/deactivate, you can send WM_MDIREFRESHMENU message to the MDI client (not frame) window whenever a window title changed.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms644919%28v=VS.85%29.aspx



来源:https://stackoverflow.com/questions/1347734/mdi-window-list-not-updating-child-title-bar-texts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!