Question Hiding console window?

Adagio

Well-known member
Joined
Dec 12, 2005
Messages
162
Programming Experience
Beginner
Is there a way to hide the console window in a Console Application?

In my console application the startup code is this:
VB.NET:
Public Class Program

    <SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.ControlAppDomain)> _
       Public Shared Sub Main()

        AddHandler Application.ThreadException, AddressOf Form1_UIThreadException

        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)

        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException

        Application.Run(New Form1())
    End Sub

    Private Shared Sub Form1_UIThreadException(ByVal sender As Object, ByVal t As ThreadExceptionEventArgs)
        ErrorHandler(t.Exception)
    End Sub

    Private Shared Sub CurrentDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
        ErrorHandler(e.ExceptionObject)
    End Sub

    Private Shared Sub ErrorHandler(ByVal e As Exception)
        MsgBox("An error has occured" & vbCrLf & e.Message, MsgBoxStyle.Critical)
    End Sub

End Class

The actual console is useless, so the console window needs to dissapeir
The obvious answer to the problem would be by turning it into a form application, but unfortunately that doesn't work. If I write the above code into the startup of a form application, an exception will be thrown (the above code wont run after any form has been created) and I need that code

Anybody who know how to fix this problem?
 
Found the solution... changing "Public Class Program" to "Module Program" made it possible to select it when selecting Windows Form Application, and causes the code to run before it's too late
 
Back
Top