How to avoid error “Constructor on type 'MyType' not found” when inheriting a base class

后端 未结 2 548
小蘑菇
小蘑菇 2020-12-17 08:25

I have a Visual Studio 2010 Windows Forms app which includes a Form base class that other classes will inherit. The base class\' constructor takes a parameter that the child

相关标签:
2条回答
  • 2020-12-17 08:47

    That is completely impossible.

    The form you see in the design view is an actual instance of your base class.
    If there is not default constructor, the designer cannot create that instance.

    You can mark the constructor with the [Obsolete("Designer only", true)], and make it throw an exception if called when not in the designer, to prevent other people from calling it.

    0 讨论(0)
  • 2020-12-17 08:55

    You need to adjust your BaseForm output type, In the properties for the project, change the Output type from Windows Application to Class Library.

    ref: https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/walkthrough-demonstrating-visual-inheritance

    0 讨论(0)
提交回复
热议问题