c# winform 把基恩士应用程序exe 嵌入到窗体源码实现
时间: 2023-08-24 07:06:31 浏览: 117
要在C# Winform中嵌入基恩士应用程序exe,可以使用Process类来启动应用程序,并将其嵌入到窗体中。以下是实现步骤:
1. 打开Visual Studio中的Winform项目,并在工具箱中添加一个Panel控件。
2. 在代码中使用Process类的Start方法来启动基恩士应用程序exe,并将其嵌入到Panel控件中。
3. 设置基恩士应用程序exe的属性和方法,以便与其进行交互。
以下是代码示例:
```csharp
using System.Diagnostics;
using System.Windows.Forms;
namespace WinformApp
{
public partial class Form1 : Form
{
private Process process;
public Form1()
{
InitializeComponent();
// 启动基恩士应用程序exe
process = new Process();
process.StartInfo.FileName = "KeenShine.exe";
process.StartInfo.Arguments = "";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
// 将基恩士应用程序exe嵌入到Panel控件中
process.WaitForInputIdle();
SetParent(process.MainWindowHandle, panel1.Handle);
// 设置窗体大小和位置
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.WaitForInputIdle();
MoveWindow(process.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
// 设置基恩士应用程序exe的属性和方法
process.StandardInput.WriteLine("Command1");
var result = process.StandardOutput.ReadLine();
// ...
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
// 关闭基恩士应用程序exe
process.Kill();
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
}
}
```
在上面的代码中,panel1是Winform中的一个Panel控件,用来显示基恩士应用程序exe。你需要根据实际情况设置基恩士应用程序exe的属性和方法。需要注意的是,在关闭窗体时,需要使用Process类的Kill方法来关闭基恩士应用程序exe。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)