【发布时间】:2012-01-25 22:15:52
【问题描述】:
我的应用程序MainForm 和HexCompare 中有两个表单。如果我点击我的应用程序到另一个窗口,然后我点击两个表单之一,只有其中一个出现在前面。我怎样才能做到这一点,如果我单击两个表单中的任何一个,它会将两者都带到应用程序中所有打开的表单的顶部?现在我需要单独选择每个表单以将它们放在我的窗口堆栈的顶部(这可能非常烦人,因为HexCompare 将ShowInTaskbar 设置为false
以我想要的方式工作的一个很好的例子是大多数“查找”对话框的工作方式。如果单击查找对话框,如果它被另一个应用程序隐藏,它会将主窗体带到前面,如果单击主窗体,如果它被另一个应用程序隐藏,则查找对话框将位于前面。
MainForm 是如何被调用的。
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
HexCompare 是如何被调用的
private void lstCaputres_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedItem = (Tuple<DateTime, byte[]>)lstCaputres.SelectedItem;
if (hexCompare == null || hexCompare.IsDisposed)
{
hexCompare = new HexCompare(selectedItem.Item2);
hexCompare.Show();
}
else
hexCompare.ChangeValue(selectedItem.Item2);
}
编辑:
看来HexCompare 的Parent 的值是Null。如果我能以某种方式将其设置为 MainForm 会解决我的问题吗?如果可以,我该如何设置?
EDIT2:
我已经使用 Tigran 的解决方案半解决了它,但它会导致闪烁,因为每个表单都被带到前面,如果有更好的解决方案我仍然感兴趣。
//In MainForm.cs
private void MainForm_Activated(object sender, EventArgs e)
{
hexCompare.BringToFront();
this.BringToFront();
}
//in HexCompare.cs
private void HexCompare_Activated(object sender, EventArgs e)
{
parent.BringToFront();
this.BringToFront();
}
【问题讨论】: