[英]c# mainui drops behind other windows, issue with topmost
我在最高級別上遇到問題,找到了一個可以“工作”的解決方案,但看起來不太好。 還有另一種“更清潔”的方法可以解決此問題嗎? 這是我的代碼:代碼中事件的注釋。
OrderTemplateView template;
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (template != null)
{
template.Close(); //must close to trigger close event.
template.Dispose();
}
mainUi.TopMost = true; // must set my mainUi topMost here othervise it drops in the background of other windows open at the computer.
template = new OrderTemplateView(this);
template.TopMost = true;// must set my dialog topmost othervise it drops behind my mainUi
template.StartPosition = FormStartPosition.CenterParent;
mainUi.TopMost = false;//must release my topmost so other windows on the computer can be called to front.
template.TopMost = false;
template.ShowDialog();
}
更新的代碼執行相同的工作:
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (template != null)
{
template.Close();
template.Dispose();
}
template = new OrderTemplateView(mainUi);
template.StartPosition = FormStartPosition.CenterParent;
template.ShowDialog(mainUi);
}
`
而不是設置TopMost,請嘗試以下操作:
刪除所有對TopMost
的引用
調用mainUi.BringToFront()
調用template.ShowDialog(mainUi)
,注意將父控件傳遞到對話框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.