如何将命令行开关添加到 VB.NET WinForms 应用程序(当来自 CMD 的 运行 时)?
How do you add command line switches to VB.NET WinForms application (when run from CMD)?
我正在创建一个基于 GUI 的应用程序 (VB.NET);当从命令行 运行 并且不显示 GUI 时,我希望它有开关(例如 -s
、-r
、-a
等)。
我已经尝试了很多方法,但它们都不起作用,即使是微软自己的方法也是如此。
请帮助我。研究了一天
将您的启动表单设置为 .visible = false
。
然后在Form_Load
事件中:
' Loop through the passed arguments
For Each argument As String In My.Application.CommandLineArgs
' Do stuff. i.e.:
if argument = "-s" then
' Do something
End if
if argument = "-r" then
' Do something
End if
if argument = "-a" then
' Make the form visible
Me.Visible = True
End if
Next
此外,如果您打算永远不使用 GUI,只需制作一个控制台应用程序而不是 winforms 应用程序。
我正在创建一个基于 GUI 的应用程序 (VB.NET);当从命令行 运行 并且不显示 GUI 时,我希望它有开关(例如 -s
、-r
、-a
等)。
我已经尝试了很多方法,但它们都不起作用,即使是微软自己的方法也是如此。
请帮助我。研究了一天
将您的启动表单设置为 .visible = false
。
然后在Form_Load
事件中:
' Loop through the passed arguments
For Each argument As String In My.Application.CommandLineArgs
' Do stuff. i.e.:
if argument = "-s" then
' Do something
End if
if argument = "-r" then
' Do something
End if
if argument = "-a" then
' Make the form visible
Me.Visible = True
End if
Next
此外,如果您打算永远不使用 GUI,只需制作一个控制台应用程序而不是 winforms 应用程序。