如何在c#中从exe为Windows窗体应用程序赋值 [英] how to assign values to a windows form application from exe in c#

查看:89
本文介绍了如何在c#中从exe为Windows窗体应用程序赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从命令提示符调用这样的exe

@BatchFiles +\\ABC.exe+ 文件 ++ 模板 +

文件和模板是两个文件夹路径,有一个txt文件和一个doc文件。



我有在c#中创建了一个Windows窗体并创建了一个exe,当我需要调用exe

时如何在windows应用程序中的load事件中设置文件和模板值,这样它将从中获取相同的值命令提示符。



暂时我硬编码路径



I have to call an exe like this from the command prompt
@BatchFiles + "\\ABC.exe " + File + " " + template +"
File and template are two folder paths having a txt file and a doc file.

I have created a Windows form in c# and created an exe, when i need to call the exe
how to set the File and template value at the load event in windows application so it will take the same value from the command prompt.

For time being i hardcode the path

string mhtfile = @"D:\Users\\Desktop\_1707.mht";
 string template = @"C:\Files\Template\N.docx";





请帮助我如何用h设置这些值ardcode。



提前谢谢



Please help me how to set these values with out hardcode.

Thanks in advance

推荐答案

为什么不使用程序参数:

Why not use the program arguments:
string[] args = Environment.GetCommandLineArgs();
if (args.Length >= 3)
    {
    string mhtfile = args[1];
    string template = args[2];
    }



然后只需使用以下值运行您的应用程序:


Then just run your app with the values:

MyApp "D:\Users\\Desktop\_1707.mht" "C:\Files\Template\N.docx"


你可以使用在Load事件中跟随Code。

这与在控制台应用程序中的工作方式相同。



MSDN Referenz



You can use the following Code in the Load event.
This works the same as it does in an Console Application.

MSDN Referenz

string[] args = Environment.GetCommandLineArgs();

foreach(string arg in args)
{

}


您可以使用 Environment.GetCommandLineArgs :

http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs%28v=vs.110%29.aspx [ ^ ]



但我建议使用像CommandLineParser这样的软件包:

https://commandline.codeplex.com/ [ ^ ] < br $> b $ b

祝你好运!
You can read the values using Environment.GetCommandLineArgs:
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs%28v=vs.110%29.aspx[^]

But I would recommend using a package like CommandLineParser:
https://commandline.codeplex.com/[^]

Good luck!


这篇关于如何在c#中从exe为Windows窗体应用程序赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆