How to run a console application without showing the console window
vb.net, visual-studio
Solution
"or alternatively how to code a main menu that will launch one of the other three forms (but making them the startup form)."
Start with a standard WinForms Project and use the Application.Startup() event. From there you can check your startup parameters and then dynamically change the Startup form by assigning your desired instance to "My.Application.MainForm". This will cause that form to load as if it was the one originally assigned to the "Startup Form" entry.
Click on Project --> Properties --> Application Tab --> "View Application Events" Button (bottom right; scroll down). Change the Left dropdown from "(General)" to "(MyApplication Events)". Change the Right dropdown from "Declarations" to "Startup".
Simplified code:
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(sender As Object, e As ApplicationServices.StartupEventArgs) Handles Me.Startup
If True Then
My.Application.MainForm = New Form1 ' <-- pass your desired instance to MainForm
End If
End Sub
End Class
End Namespace
Problem
I have written an application with the following sub main: ``` Public Sub Main() Dim Value As String() = Environment.GetCommandLineArgs Dim F As Form Select Case Value.Last.ToLower Case "-character" F = New frmCharacterSheet Case "-viewer" F = New frmClient Case Else F = New frmCombat End Select Application.Run(F) End Sub ``` This is because I want to be able to install my app with three different startup modes based on the command line. I did have a form that did this, but this has made error trapping very hard because the main form just reports the error. This console seems to work well but I don't want the user to see the black console screen at startup. I have searched for the answer but most solutions are 'switch back to a windows forms application'. I don't want to do this though for the above reason. (I cannot use application.run(f) in a winforms start situation because I get a threading error. I need to know either how to hide the console window, or alternatively how to code a main menu that will launch one of the other three forms (but making them the startup form). Any help would be appreciated....