C# - 是否可以创建一个Windows窗体应用程序,可以从命令行参数运行? [英] C# - Is it possible to create a Windows Forms application that can run from the command line with parameters?
本文介绍了C# - 是否可以创建一个Windows窗体应用程序,可以从命令行参数运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个Windows窗体应用程序,它将包含一个UI,但我想让它从命令行运行一些参数,可能还有一个 / hide
或 / visible = false
选项。
I would like a Windows Forms application that will contain a UI, but I want it to run from the command line with some parameters, possibly also a /hide
or /visible=false
option.
如何读取命令行参数?
How is it possible to read in the command line parameters? And adjust accordingly?
推荐答案
如果您更改此默认主签名:
If you change this default Main signature:
[STAThread]
static void Main()
到此:
[STAThread]
static void Main(String[] args)
您可以像从普通控制台应用程序那样访问命令行变量,或者如果您想从其他地方访问它们,使用:
You can access the commandline variables as you would from a normal console app, or if you want to access them from elsewhere you can use:
System.Environment.GetCommandLineArgs();
这篇关于C# - 是否可以创建一个Windows窗体应用程序,可以从命令行参数运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文