1

我是开发 Wpf 的初学者,我需要知道如何.exe在新TabItemTabControl控件中运行应用程序。我做了这个片段:

 private void MenuItem_Click_6(object sender, RoutedEventArgs e) { 
    TabItem nPage = new TabItem();
    nPage.Header = "nouveau";
    TabPage.Items.Add(nPage);
    ProcessStartInfo pInfo = new ProcessStartInfo("Multi-langue.exe");
    pInfo.WorkingDirectory = @"C:\Multi-langue\Multi-langue\bin\Debug";
    Process p = Process.Start(pInfo);
    }

新应用程序正在运行,但不在新的TabItem.

那么如何修改我的代码片段以集成在第一个应用程序中启动的第二个应用程序的显示?

4

1 回答 1

6

我找到了这个解决方案,它工作正常

 public IntPtr MainWindowHandle { get; set; }
          [DllImport("user32.dll", SetLastError = true)]
        private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

  private void MenuItem_Click_6(object sender, RoutedEventArgs e) { 

        TabItem nPage = new TabItem();
        WindowsFormsHost host = new WindowsFormsHost();
        System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
        host.Child = p;
        nPage.Header = "nouveau";
        nPage.Content = host;
        TabPage.Items.Add(nPage);
        Process proc = Process.Start(
   new ProcessStartInfo()
   {
       FileName = @"C:\Multi-langue\Multi-langue\bin\Debug\Multi-langue.exe",

       WindowStyle = ProcessWindowStyle.Normal
   });
        Thread.Sleep(1000);
        SetParent(proc.MainWindowHandle, p.Handle);

    }
于 2013-09-25T13:51:52.940 回答