Mandatory method call

In VB.NET, when you create a custom control class, you have a duty to call sub InitializeComponent inside the constructor.

If you do not, a warning message appears:

'Public Sub New ()' in the type created by the designer, "MyUserControl" should call the InitializeComponent Method.

What is the mechanism used to raise this warning? Is this something I can reproduce for my own functions?

+2
source share
1 answer

This is the built-in behavior for the VB.NET compiler. This sample class runs it:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Class1
    Public Sub New()
       '' Warning BC40054 generated here
    End Sub
End Class

. , , , .

+1

All Articles