[英]How can we create a dynamic sql query to run without considering if the parameters are passed or not in c# windows forms
[英]C# - Is it possible to create a Windows Forms application that can run from the command line with parameters?
我想要一個包含UI的Windows窗體應用程序,但我希望它從命令行運行一些參數,可能還有/hide
或/visible=false
選項。
如何讀取命令行參數? 並相應調整?
如果更改此默認主簽名:
[STAThread]
static void Main()
對此:
[STAThread]
static void Main(String[] args)
您可以像訪問普通控制台應用程序一樣訪問命令行變量,或者如果要從其他地方訪問它們,可以使用:
System.Environment.GetCommandLineArgs();
[STAThread]
static void Main(string[] args)
{
if (args.Length == 0)
{
// Run the application in a windows form
Application.Run(new MainForm( ));
}
else
{
// Run app from CLI
Console.WriteLine(DoStuff(args));
}
}
是的,它應該可以將項目創建為普通的Windows應用程序項目。 然后在啟動窗口之前的program.cs中,調用Environment.GetCommandLineArgs()
來獲取命令行參數並解析它們以執行您想要的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.