我这个是一个winform 调用的另一个winform程序 传递的时候这样写
参数 1 2之间用空格分开
System.Diagnostics.Process.Start(Application.StartupPath + "\\test.exe ", "参数1 参数2");
我们就是要实现这种功能!这样的程序可以在任何一个项目中使用,
通过System.Diagnostics.Process.Start("你的程序.exe 参数1")。
一般情况下,每个项目都有一个Main函数,它是整个程序的入口点,那么参数也肯定在这里被传递!
默认的Main函数:
/// <summary> /// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
我们只需改成这样:
/// <summary> /// 应用程序的主入口点。
/// </summary> [STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length == 0)
Application.Run(new Form1());
else
Application.Run(new Form1(args));
}
Form1窗体的构造:
string[] args=null;
public Form1()
{
InitializeComponent();
}
public Form1(string[] args)
{
InitializeComponent();
this.args = args;
}
真的是很简单很简单的几行代码。。。我们有了args参数,剩下的代码。。。看你的需求咯。