概要
有时候一个项目有数个程序组成,一个个的控制,使用起来很不方便,我们可以用一个程序把这些程序都管理起来,使用起来要方便些。
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 控制执行文件
{
public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
Process process = new Process();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//process.StartInfo.FileName = @"E:\test\控制执行文件\测试程序\bin\Debug\测试程序.exe";
process.StartInfo.FileName = ConfigurationManager.AppSettings["sb1"];
process.Start();
}
private void button3_Click(object sender, EventArgs e)
{
DisPlayWindow(process.MainWindowHandle,1);
}
public int DisPlayWindow(IntPtr hwnd, int nCmdshow) {
return ShowWindow(hwnd, nCmdshow);
}
private void button4_Click(object sender, EventArgs e)
{
DisPlayWindow(process.MainWindowHandle, 2);
}
private void button2_Click(object sender, EventArgs e)
{
process.Kill();
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="sb1" value="E:\test\控制执行文件\测试程序\bin\Debug\测试程序.exe"/>
</appSettings>
</configuration>
运行效果
引用