winform中,如何让弹出的另一个窗体显示现有窗体前端
假设有两个程序,分别为“A.exe”、“B.exe”,分别是来自两个不同的解决方案,我在A中用Process.Start("B.exe"); 实现了启动同一目录下的B,此时如何保持B始终在A之前,如果B窗口不取消,则无法在A上操作?
ps:可能表达地不清楚,平时在一些程序中也碰到过类似的,就像这样
此时再点击“系统属性”窗口无法选中。 WinForm 前端
[解决办法]
你截图里面的是ShowDialog,模态对话框。
你说的两个exe是两个独立的进程,不一样的场景。
你要这个效果的话,可能要换一下思路了,楼下请继续~
[解决办法]
在A程序的Form1里,获取到B程序的窗口Form2,然后
private void Form1_Activated(object sender, EventArgs e)
{
Form2.BringToFront();
}
Form.FromHandle(process.MainWindowHandle).BringToFront();
IntPtr hWnd = (IntPtr)FindWindow(null, Title);
if (hWnd != IntPtr.Zero)
{
bool isIcon = IsIconic(hWnd);
if (!isIcon)
{
SetForegroundWindow(hWnd);
}
else
{
OpenIcon(hWnd);
}
}
title就是要激活的窗口标题
[解决办法]
你既然是不同解决方案的,用的是进程访问的EXE文件么?
那用委托吧
启动前将主画面设为this.Enabled =FALSE
p.SynchronizingObject = this;
p.Exited += (sender, e) =>
{
this.Enabled = true;
};
p.EnableRaisingEvents = true;
还是不行啊!!!大侠们,帮我写个实例吧!!!
if (hwnd != IntPtr.Zero)
{
SetForegroundWindow(hwnd);
//Process.Start(@"C:\Documents and Settings\10989889a\桌面\反汇编工具.exe");
//IntPtr hWnd = (IntPtr)FindWindow(null, "打开文件 - 安全警告");
SetParent(hwnd, this.Handle);
////DialogBoxParam(hWnd, null, this.Handle, IntPtr.Zero, IntPtr.Zero);
}
[解决办法]