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

后端 未结 2 571
小蘑菇
小蘑菇 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.

提交回复
热议问题