問題描述
我有一個 MDI 容器表單,以及一些獨立更新其標題欄文本的子表單.在子窗體上更改 Text 屬性后,當打開菜單時,子窗體中的新標題欄文本不會在窗口列表菜單中更新.這是 .NET 通過 MdiWindowListItem 屬性提供的自動生成的窗口列表.
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:
- 主 MenuStrip 上的 Update()
- Refresh() 在主 MenuStrip 上
- Invalidate() 在窗口 MenuStrip 上
- 在運行時對窗口列表項之一進行 Invalidate()
- 在運行時在窗口列表項之一上切換 Checked 狀態兩次
似乎沒有任何其他遠程可行的函數可以在菜單項、其父 ToolStrip 或包含菜單系統的父窗體上調用.
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.
推薦答案
上述解決方案對我不起作用.但我按照鏈接,發現了這個,效果很好:
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);
}
}
謝謝!
這篇關于MDI 窗口列表不更新子標題欄文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!