网络表单面板中另一个应用程序的定位

问题描述 投票:0回答:1

帖子引导

如何在 C# 程序的面板中运行另一个应用程序?

我正在 Webform 面板中运行该应用程序。 但是应用程序的左上角与面板的左上角不对齐。

无论面板大小如何,面板边缘和应用程序窗口之间总是显示出很大的间隙。

关于如何在面板中对齐侧面应用程序有什么想法吗?

代码:

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


private void Form1_Load(object sender, EventArgs e)
{
    ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
    psi.WindowStyle = ProcessWindowStyle.Minimized;
    Process p = Process.Start(psi);
    Thread.Sleep(500);
    SetParent(p.MainWindowHandle, panel1.Handle);
    CenterToScreen();
    psi.WindowStyle = ProcessWindowStyle.Normal;
}
c# winforms exe panel
1个回答
0
投票

感谢吉米, 这真的很简单:

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll")]
internal static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

private void Form1_Load(object sender, EventArgs e)
{
   ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
   Process p = Process.Start(psi);
   Thread.Sleep(500);
   SetParent(p.MainWindowHandle, panel1.Handle);
   MoveWindow(p.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
}
© www.soinside.com 2019 - 2024. All rights reserved.