問(wèn)題描述
我有一個(gè) MDI 容器表單,以及一些獨(dú)立更新其標(biāo)題欄文本的子表單.在子窗體上更改 Text 屬性后,當(dāng)打開(kāi)菜單時(shí),子窗體中的新標(biāo)題欄文本不會(huì)在窗口列表菜單中更新.這是 .NET 通過(guò) MdiWindowListItem 屬性提供的自動(dòng)生成的窗口列表.
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.
僅當(dāng)另一個(gè)事件物理更改窗口列表(打開(kāi)一個(gè)新子項(xiàng)、關(guān)閉一個(gè)子項(xiàng)、切換到另一個(gè)子項(xiàng))時(shí),更改才會(huì)傳播.
The change only propagates when another event changes the window list physically (opening a new child, closing a child, switching to another child).
有沒(méi)有辦法以編程方式強(qiáng)制更新窗口列表?我已經(jīng)有一些代碼可以在更改子標(biāo)題欄文本的同時(shí)啟用/禁用菜單.
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.
我嘗試了以下方法但沒(méi)有成功:
I tried the following with no success:
- 主 MenuStrip 上的 Update()
- Refresh() 在主 MenuStrip 上
- Invalidate() 在窗口 MenuStrip 上
- 在運(yùn)行時(shí)對(duì)窗口列表項(xiàng)之一進(jìn)行 Invalidate()
- 在運(yùn)行時(shí)在窗口列表項(xiàng)之一上切換 Checked 狀態(tài)兩次
似乎沒(méi)有任何其他遠(yuǎn)程可行的函數(shù)可以在菜單項(xiàng)、其父 ToolStrip 或包含菜單系統(tǒng)的父窗體上調(diào)用.
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.
推薦答案
上述解決方案對(duì)我不起作用.但我按照鏈接,發(fā)現(xiàn)了這個(gè),效果很好:
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);
}
}
謝謝!
這篇關(guān)于MDI 窗口列表不更新子標(biāo)題欄文本的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!