2

我有一个BaseForm用于保存设置的基本表单。此表单中没有控件,它在设计器中作为空表单打开。但是,当我继承这个表单时,设计器拒绝在设计器中打开新创建的表单(设计器中没有按钮查看)。可能是什么问题?谢谢

4

2 回答 2

3

问题出在.csproj文件上。

每个表单在文件中都有这样的签名

<Compile Include="Opers\MyForm.cs">
  <SubType>Form</SubType>
</Compile>

SubType元素说这实际上是一个表单,在我的文件中,由于某种原因它被删除了。

于 2013-01-02T14:53:48.433 回答
2

I would highly recommend to avoid inheriting forms whenever possible. For saving settings, this is surely avoidable: make yourself an FormSettingsSaver class or something like that and pass it the form as argument when loading/closing, etc. Inheriting forms can make a lot of headaches and MS isn´t really putting any work in WindowsForms and/or the Designer.

edit: if you want to stick with inheriting forms, check the link from rene in the comment. Most designer problems can be avoided with checking for DesignMode. You could also try to comment out statements until you find the culprit. All code in the constructor and (i think) OnLoad is executed when the form is displayed in the Designer, so there would be a good place to start.

于 2012-12-28T21:39:59.457 回答