Reputation: 13
When using inheritance on Winforms, it causes the class to appear Shared. Why only the second line in the Main method displays a syntax warning? TestForm102.Widgets.Count should highlight the same issue.
Note: I added the MustInherit to TestForm101 to highlight the issue (...what it should display). If I remove it, the form simply acts like it is shared too.
Upvotes: 1
Views: 98
Reputation: 9981
The first line works because TestForm102
is an instance of TestForm102
rather than a type as one would expect. It's auto-generated by VS and you'll find it in My.Forms. You're last line fails because VS cannot auto-generate an instance of a MustInherit
form and/or a form without a public parameterless constructor. At this point TestForm101
is a type, and as observed, you cannot reference a non-shared member without an object reference.
Dim y As Integer = My.Forms.TestForm102.Widgets.Count '<-Ok
Dim x As Integer = My.Forms.TestForm101.Widgets.count '<-Error
Error: 'TestForm101' is not a member of ...MyForms
Upvotes: 2