VB.NET: where is default constructor of a windows form?
where can I find the default c开发者_StackOverflow社区onstructor of a windows form? I mean:
Public Sub New()
End Sub
I should say that I Use Visual Studio 2008 as my editor.
It doesn't show up by default. You can declare one, and it will override the default constructor. In fact, as soon as you type in Public Sub New() and hit enter, VS should fill in a couple of lines of code, and you can add your code where needed.
A default (Public) constructor for any VB Class does not need to be defined explicity. In addition, in the .Designer.vb file, Forms include a DesignerGeneratedAttribute, which automatically adds a call to InitializeComponent
to the default constructor, and complains if your manually added constructor does not.
There is no default constructor as long as you did not write any. So add the code snippet of your question to the file MyForm.vb and you are happy. VS will typically add a call to InitializeComponent()
to it, which makes sense.
精彩评论