c打开一个windows窗体应用程序另一个

本文关键字:windows 一个 窗体 应用程序 另一个 | 更新日期: 2025-02-19 09:27:51

我试图从另一个打开一个wfapp,当我运行代码时:System.dll中发生了类型为"System.ComponentModel.Win32Exception"的未处理异常有一个代码:

private void button2_Click(object sender, EventArgs e)
    {
        Panel panel1 = new Panel();

        Process p = Process.Start("ap.exe");
        //Thread.Sleep(500); // Allow the process to open it's window
        SetParent(p.MainWindowHandle, panel1.Handle);
    }
    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

c打开一个windows窗体应用程序另一个

出现此错误的原因是,您的代码找不到ap.exe,请给出正确的路径。

当找不到指定给Process的文件名时,我能够重现同样的错误。

印度程序员的回答是正确的。

你的路径应该是这样的:

"C:'Users'YourUser'Documents'Visual Studio 2013'Projects'Yourapp'Yourapp'bin'debug'ap.exe"

假设您正在使用VS 2013并对其进行调试。

如果您只使用"ap.exe",那么它应该存在于调试文件夹中,否则它将找不到它。

相关文章: