Start VB.NET GUI app using Sub Main or form startup object?

后端 未结 4 1998
一整个雨季
一整个雨季 2021-01-01 22:18

Is there any reason to start a GUI program (application for Windows) written in VB.NET in the Sub Main of a module rather than directly in a form?

EDIT: The program

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 22:48

    Yes, and I have done it a few times.

    One reason is, that if your app is COM EXE (speaking now from a VB6 point of view) then you want to be able to detect in what context the EXE is being called (being launched or being spoken to by some other app).

    For example:

    Sub Main()
        If App.StartMode = vbSModeAutomation Then
            ...
        Else
            ...
        End If
    End Sub
    

    Another is if you want your app to be able to handle any command line parameters.

    For example:

    Sub Main()
        If App.PrevInstance Then End
        If InStr(Command, "/s") > 0 Then
            Form1.Show
        ElseIf InStr(Command, "/p") > 0 Then
            LoadPicture ("c:\windows\Zapotec.bmp")
        End If
    End Sub
    

    (from one of my attempts to make a screen saver)

提交回复
热议问题