There may be many times you want to have your application read the arguments (if any) that were passed to it. To do so, first add a new blank code file (if you don't have a template for a blank code file, you can just add a class and delete the code it puts in it) and call it "MyArguments.vb", or something like that. Once you have added that file, add this code in it:
vb
Namespace My
Class MyApplication
#If _MyType = "WindowsForms" Then
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As ApplicationServices.StartupEventArgs) Handles Me.Startup
'*******************************************************
'* This is the sub that fires when your application starts. You can *
'* read the arguments from here. *
'*******************************************************
End Sub
'OnInitialize is used for advanced customization of the My Application Model (MyApplication).
'Startup code for your specific application should be placed in a Startup event handler.
<Global.System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean
Return MyBase.OnInitialize(commandLineArgs)
End Function
#End If
End Class
End Namespace
Look for the MyApplication_Startup() method in that code. That is the method that fires when your application starts, and that is also the method where you can read what arguments were passed to it. The arguments are stored in the parameter e, which is of type
ApplicationServices.StartupEventArgs. To access the collection of arguments passed to your application, use the
vb
parameter, which is a Collection(Of String) and each member is a different argument. To get the number of arguments passed to your application, you could use
vb
Now you can see what arguments were passed to your application, but really, what's the good of knowing them if you cant do anything about them? So, here i will explain a few things you can do from the MyApplication_Startup() method.
If the startup form of your application depended on what argument(s) were passed to it, you can change the startup form with the property
vb
You can change weather or not to render XP visual styles on your application with the property
vb
You can change (or remove) the splash screen of your application with the property
vb
You can change the shutdown style of your application with the property
vb
That is only an example of what you can do in the MyApplication_Startup() method. Play around a bit with the Me and Application classes. You will find there is a lot more you can do.