表单子类的子类显示为空

发布于 2024-07-16 02:59:51 字数 577 浏览 2 评论 0原文

我正在编写一个应用程序,其中有不确定数量的表单,需要特定的弹出功能(类似于 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 类中的属性放在新表单上,但没有帮助。 我需要能够更改表单的内容,但我看不出有什么问题,所以这既令人烦恼又令人困惑。

I am writing an application where I have indeterminate amount of Forms that require a certain popup-functionality (similar to MSN, a little window at the bottom right of the screen). I wrote the first form, then thought that I could copy the file to make a new one. So far so good. A bit later I realized that I could have subclassed Form, written my popup code, then subclassed my new PopupForm class to make the other forms, to simplify rewriting the popup code. So I did that, but now my forms don't show up properly in the Designer! They are completely white (no background image or controls) and I can't drag new controls onto it. I tried placing the

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

attributes from the Form class on my new form, but it didn't help. I need to be able to alter the contents of my forms, and I don't see what's wrong, so this is both annoying and confusing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-07-23 02:59:51

如果您有多个构造函数,请确保您调用的是调用基本无参数构造函数的构造函数,即包含 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
       { }
  }

If you have multiple constructors, make sure that you call the one which calls the base parameterless constructor, i.e. the one which contains 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
       { }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文