首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform中,怎么让弹出的另一个窗体显示现有窗体前端

2013-07-16 
winform中,如何让弹出的另一个窗体显示现有窗体前端假设有两个程序,分别为“A.exe”、“B.exe”,分别是来自两个

winform中,如何让弹出的另一个窗体显示现有窗体前端
假设有两个程序,分别为“A.exe”、“B.exe”,分别是来自两个不同的解决方案,我在A中用Process.Start("B.exe");   实现了启动同一目录下的B,此时如何保持B始终在A之前,如果B窗口不取消,则无法在A上操作?
ps:可能表达地不清楚,平时在一些程序中也碰到过类似的,就像这样
winform中,怎么让弹出的另一个窗体显示现有窗体前端
此时再点击“系统属性”窗口无法选中。 WinForm 前端
[解决办法]
你截图里面的是ShowDialog,模态对话框。
你说的两个exe是两个独立的进程,不一样的场景。
你要这个效果的话,可能要换一下思路了,楼下请继续~
[解决办法]
在A程序的Form1里,获取到B程序的窗口Form2,然后


        private void Form1_Activated(object sender, EventArgs e)
        {
             Form2.BringToFront(); 
        }

[解决办法]
找到目标程序主窗口(比如用FindWindow)
然后用SetParent将它的父窗口设置为第一个窗口,那么它永远在第一个窗口前面。
[解决办法]
或者,把Process.Start("B.exe")改为反射,然后ShowDialog
[解决办法]
引用:
Quote: 引用:

在A程序的Form1里,获取到B程序的窗口Form2,然后


        private void Form1_Activated(object sender, EventArgs e)
        {
             Form2.BringToFront(); 
        }

请问大侠,B里的的窗口在A程序中又要如何获取呢


这样可以不,你测试一下,我没有测试过!

            Form.FromHandle(process.MainWindowHandle).BringToFront();

[解决办法]
[System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string strclassName, string strWindowName);




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;

[解决办法]
引用:
还是不行啊!!!大侠们,帮我写个实例吧!!!

-----------------

声明三个API:FindWindow,SetParent,SetForegroundWindow
调用计算器为例: Process.Start("calc");
            Thread.Sleep(1000);
            IntPtr hwnd = FindWindow(null, "计算器");


            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);
            }


[解决办法]

引用:


[System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool OpenIcon(IntPtr hWnd);

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool IsIconic(IntPtr hWnd);

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern int SetForegroundWindow(IntPtr hWnd);

热点排行