简体   繁体   English

如何将命令行开关添加到 VB.NET WinForms 应用程序(从 CMD 运行时)?

[英]How do you add command line switches to VB.NET WinForms application (when run from CMD)?

I am creating a GUI-based application (VB.NET);我正在创建一个基于 GUI 的应用程序 (VB.NET); I want it to have switches (such as -s , -r , -a , etc.) when run from the command line and not display the GUI.我希望它在从命令行运行而不显示 GUI 时具有开关(例如-s-r-a等)。

I have already tried a plethora of methods, but they do not work, even the ones from Microsoft themselves.我已经尝试了很多方法,但它们都不起作用,即使是微软自己的方法。

Please help me.请帮我。 I have been researching for a day now.我已经研究了一天。

Set your startup form to .visible = false .将您的启动表单设置为.visible = false

Then in the Form_Load event:然后在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

Also, if you're planning to never use the GUI, just make a console app instead of a winforms app.此外,如果您打算从不使用 GUI,只需制作控制台应用程序而不是 winforms 应用程序。

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

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