加入Windows Forms C# [英] Join Windows Forms C#

查看:73
本文介绍了加入Windows Forms C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个程序可以打开一个程序.我希望将两个表单合并在一起,以便它们以一个表单的形式移动,然后分离回2个独立的表单,或者在它们都运行时将它们分开.

I have two programs that open one form a piece. I looking to, if I want, join the two forms together so they move as one then separate back into 2 independent forms or just keep them separate when they are both running.

推荐答案

如果我理解正确,您想让两个单独的应用程序以相同的形式运行吗?

那比看起来容易!

拿一个新的应用程序winforms.
在表单上,​​放置两个面板,使它们覆盖客户区域.锚定它们,以便在表单显示时调整大小.
对于每个面板,运行应用程序,并将其附加到面板上:
If I understand you correctly, you want to have two separate applications running in the same form?

That''s easier than it seems!

Take a new application, winforms.
On the form, place two panels so the they cover the client area. Anchor them so that they resize when the form does.
For each panel, run the application, and attach it to the panel:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent);
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);

private const short SWP_NOMOVE = 0X2;
private const short SWP_NOSIZE = 1;
private const short SWP_NOZORDER = 0X4;
private const int SWP_SHOWWINDOW = 0x0040;

    Process process = Process.Start("calc.exe");
    while (!IsWindowVisible(process.MainWindowHandle))
        {
        Thread.Sleep(10);
        }
    IntPtr processHandle = process.MainWindowHandle;
    SetParent(processHandle, myPanel.Handle);
    SetWindowPos(processHandle, 0, 0, 0, myPanel.Bounds.Width, myPanel.Bounds.Height, SWP_NOZORDER | SWP_SHOWWINDOW);


这篇关于加入Windows Forms C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆