简体   繁体   English

如何使用Windows窗体中的参数打开多个文件

[英]How to open multiple files using arguments from windows forms

I know how to open an external application within a windows forms application and a file using an argument. 我知道如何使用参数在Windows窗体应用程序和文件中打开外部应用程序。 Is there a way to pass multiple argument to open more than one file at a time. 有没有一种方法可以传递多个参数来一次打开多个文件。 At the moment file2 simply overwrites file1. 目前,file2仅覆盖file1。 Im using Visual Studio 2017 windows forms C#, thanks. 我正在使用Visual Studio 2017 Windows窗体C#,谢谢。

                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = (app + ".exe");
                    startInfo.Arguments = file1;
                    startInfo.Arguments = file2;
                    Process.Start(startInfo);

It very much depends on the application you're launching. 这在很大程度上取决于您要启动的应用程序。 Does it support opening multiple files via command line? 是否支持通过命令行打开多个文件? You would have to check its command line arguments. 您将必须检查其命令行参数。

If you made the other application, you can pass multiple arguments to the Arguments property by separating them with spaces. 如果创建了另一个应用程序,则可以通过使用空格将多个参数传递给Arguments属性。 Note that you'll also have to put them in quotes if there are spaces in their paths. 请注意,如果它们的路径中有空格,则还必须将它们用引号引起来。

So to launch the application you would do something like this: 因此,要启动该应用程序,您将执行以下操作:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = (app + ".exe");
startInfo.Arguments = string.Format("\"{0}\" \"{1}\"", file1, file2);
Process.Start(startInfo);

and then in the other application, you have your Main method: 然后在另一个应用程序中,您具有Main方法:

public static void Main(string[] args)
{
     // args[0] contains file1
     // args[1] contains file2
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM