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

后端 未结 4 2003
一整个雨季
一整个雨季 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

    You can do it either way, but you should really only keep code in the form that is directly related to the operations and user interface elements on that form. Application startup code isn't related to UI, normally concerned with splash screens, checking network connectivity, verifying a single instance only, setting up user configuration settings, and so on.

    After the above items (or the appropriate initialization code for your app) are complete, Sub Main can create an instance of the main form, then show it so the user can begin interacting with your application.

    This separates startup code from your form code. Later, when you're maintaining the application, you'll be glad you separated the two.

提交回复
热议问题