Windows窗体继承 [英] Windows Forms inheritance

查看:72
本文介绍了Windows窗体继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows应用程序中有一堆非常相似的表单,所以我试图将其中一个用作主表单并从中继承其他表单.
所以声明了第一种形式:

public partial class NewItemForm : Form

和后续的(例如)

public partial class NewDerivedForm : NewItemForm



我的程序似乎可以编译并执行得很好,但是当我尝试将派生的表单加载到设计器表面时,VS2010设计器却疯了,在不同的时间显示了各种错误,其中大部分是(我相信)与自动执行有关.................................................................................................... NewDerivedForm.Designer.cs文件中生成的代码.谷歌搜索使我进入了MSDN中的使用继承选择器对话框继承表单".本文与VS2003有关,但是我不认为VS2010具有继承选择器"对话框.

我看到几个危险信号.我搜索过的大多数结果都提到了我找不到的继承选择器",大多数看起来都已经很老了,而且大多数结果都在讨论Visual Basic,而不是C#.需要一个继承选择器"使我认为这并不像我想象的那么简单.

那么问题来了:我本来想做的事情(对不起的双关语)是不好的,不是正确的方法吗?我有想念的招吗?解决问题的更好方法?

我知道其中有些含糊不清,我试图将其保持通用,而不是发布几百行代码和错误消息.感谢您提供任何见解或指导.

解决方案

以下是方便的指南:

http://www.akadia.com/services/dotnet_inherited_forms.html [


I''ve got a bunch of very similar forms in my windows application, so I''m trying to use one as a master form and inherit from it for the other forms.
So the first form is declared:

public partial class NewItemForm : Form

and subsequent ones as (for example)

public partial class NewDerivedForm : NewItemForm



My program seems to compile and execute just fine, but the VS2010 designer is just going nuts when I try to load the derived forms on the designer surface, showing various errors at various times, most having to do (I believe) with the auto-generated code in the NewDerivedForm.Designer.cs file. Googling led me to "Inheriting Forms Using the Inheritance Picker Dialog Box" in MSDN. The article is relevant to VS2003, however, and I don''t think that VS2010 has an Inheritance Picker Dialog Box.

I''m seeing a couple of red flags. Most all of my googled results make mention of this ''inheritance picker'' that I can''t find, most seem to be quite old, and most of the results are discussing Visual Basic, not C#. And needing an ''inheritance picker'' makes me think that this is not as straightforward as I had thought.

So the question: Is what I''m trying to do inherently (pardon the small pun) bad, not the right approach? Is there a trick I''m missing? A better way to approach the problem?

I know some of this is vague, I''m trying to keep it general rather than post a couple of hundred lines of code and error messages. Any insights or guidance are appreciated.

解决方案

Here''s a handy guide:

http://www.akadia.com/services/dotnet_inherited_forms.html[^]


VS 2010 has it too. From the Solution Explorer context menu, choose Add New Item, select Inherited Form from the templates, this will take you to the Inheritance Picker dialog.


Rather than inheritance on forms, I usually prefer to create user controls to encapsulate common functionality that can then just be dropped onto each new form that needs it.


这篇关于Windows窗体继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆