1

我正在编写一个应用程序,其中我有不确定的数量Forms需要一定的弹出功能(类似于 MSN,屏幕右下角的一个小窗口)。我写了第一个表格,然后想我可以复制文件来制作一个新的。到目前为止,一切都很好。过了一会儿,我意识到我可以对 Form 进行子类化,编写弹出代码,然后对新PopupForm类进行子类化以制作其他表单,以简化对弹出代码的重写。所以我这样做了,但现在我的表单没有在设计器中正确显示!它们完全是白色的(没有背景图像或控件),我无法将新控件拖到上面。我试着把

[Designer("System.Windows.Forms.Design.FormDocumentDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(IRootDesigner))]
[DesignerCategory("Form")]

我的新表单上的类的属性Form,但它没有帮助。我需要能够更改表单的内容,而且我看不出有什么问题,所以这既烦人又令人困惑。

4

1 回答 1

2

如果您有多个构造函数,请确保调用调用基本无参数构造函数的那个​​,即包含InitializeComponent.

  class BaseForm
  {
       public BaseForm()
       {
            InitializeComponent();
       }

       // not good -> does not call InitializeComponent() or :this()
       public BaseForm(int someParameter)
       { }

       public BaseForm(string someParameter)
           : this() // good -> calls InitializeComponent()
       { }

       public BaseForm(byte b)
       {
           // good -> InitializeComponent is called explicitly 
           // (but call to this() above is preferred)
           InitializeComponent();
       }
  }

  class DerivedForm : BaseForm
  {
       public DerivedForm()
          : base(5) // not good -> calls the "bad" base constructor
       { }

       // good -> base() constructor is implicitly called
       public DerivedForm(double x)
       { }

       public DerivedForm(string someParam)
          : base(someParam)  // good -> BaseForm(string) will call InitializeComponent
       { }
  }
于 2009-03-16T17:55:57.910 回答