2_RA
- hrafnulf13
- Oct 1, 2020
- 1 min read
Updated: Oct 13, 2020
C#
Since C# is C-style language, we can deduce that Program.cs contains the entry point of the application. There Application [1] class invokes method Run() [2]
Application.Run(<Window form>)
which opens a specified window (in our case invokes constructor Lesson1).
Application.Run(new Lesson1())
After that constructor invokes the InitializeComponent()

VB.net
In case of VB.net, there is a similiar type of file Application.Designer.vb. It stores information related to Windows Forms applications such as the authentication mode and the shutdown mode [9]. Here we can see that it overrides the function
OnCreateMainForm() [3]
Which sets and configures the Mainform [4] of the current application to a specified one
Me.Mainform = Global.VBLesson1.VBLesson1
The method OnCreateMainForm() [3] is usually called by OnRun() [5], which according to definition
By default, this method does nothing. However, when you select a main form for your application in the Visual Basic Project Designer, the designer overrides the OnCreateMainForm method with a method that sets the MainForm property to a new instance of the main form [5].
Then, we can the class definition of the Lesson1, where there is
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Which is a part of [7], where DesignerGenerated() defined as
When applied to a class, the compiler implicitly calls a component-initializing method from the default synthetic constructor [6].
DesignerGenerated() automatically adds the call to the InitializeComponent() to the the constructor which will invoke the InitializeComponent() when the form is inialized [6, 8].
Thus, it is quite similiar procedure for both C# and VB.net.

References
https://docs.microsoft.com/en-us/dotnet/api/system.windows.application?view=netcore-3.1
https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.compilerservices.designergeneratedattribute?view=netcore-3.1
https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.compilerservices?view=netcore-3.1
https://stackoverflow.com/questions/4573596/vb-net-where-is-default-constructor-of-a-windows-form
https://www.informit.com/articles/article.aspx?p=1602817&seqNum=3
Comments