本文介绍了在WPF应用程序的新Itemtab中运行exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm beginner in developping Wpf i need to know how to run an .exe application in a new TabItem in a TabControl control.i did this snippet:

 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 内部.

the new application is running but not inside the new TabItem.

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

So How can i modify my snippet to integrate the display of the second application launched inside the first one?

推荐答案

我找到了这个解决方案,并且效果很好

i find this solution and it's works fine

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

    }

这篇关于在WPF应用程序的新Itemtab中运行exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:07
查看更多