我怎样才能获得Visual Studio 2008的Windows窗体设计来呈现,实现一个抽象基类的表单? [英] How can I get Visual Studio 2008 Windows Forms designer to render a Form that implements an abstract base class?

查看:169
本文介绍了我怎样才能获得Visual Studio 2008的Windows窗体设计来呈现,实现一个抽象基类的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事一个问题,在Windows窗体控件继承,需要它的一些建议。

I engaged a problem with inherited Controls in Windows Forms and need some advice on it.

我使用用于在列表项的基类(制成的面板的自制的GUI列表)和一些继承的是每个数据类型可被添加到列表中的控制。

I do use a base class for items in a List (selfmade GUI list made of a panel) and some inherited controls that are for each type of data that could be added to the list.

有与它没有问题,但我现在发现,这将是正确的,使基本控制一个抽象类,因为它有方法,需要在所有继承的控制来实现,从被叫基本控制在code,但绝不能,不能在基类中实现。

There was no problem with it, but I now found out, that it would be right, to make the base-control an abstract class, since it has methods, that need to be implemented in all inherited controls, called from the code inside the base-control, but must not and can not be implemented in the base class.

当我迎来基控制为抽象的视觉 &工作室NBSP; 2008年设计师拒绝加载窗口

When I mark the base-control as abstract, the Visual Studio 2008 Designer refuses to load the window.

有没有一种方式来获得与基本控制的设计工作提出了抽象的?

Is there a way to get the Designer work with the base-control made abstract?

推荐答案

我知道必须有一个方法可以做到这一点(我找到了一个办法做到这一点干净)。盛的解决方案是什么我想出了一个临时的解决方法,但经过朋友指出,最终从一个抽象继承了表格类,我们应该能够完成这件事。如果他们能做到这一点,我们可以做到这一点。

I KNEW there had to be a way to do this (and I found a way to do this cleanly). Sheng's solution is exactly what I came up with as a temporary workaround but after a friend pointed out that the Form class eventually inherited from an abstract class, we SHOULD be able to get this done. If they can do it, we can do it.

我们从这个code到这个问题。

We went from this code to the problem

Form1 : Form

问题

public class Form1 : BaseForm
...
public abstract class BaseForm : Form

这就是最初的问题发挥了作用。正如前面所说的,有朋友指出, System.Windows.Forms.Form中实现了一个基类是抽象的。我们能找到...

This is where the initial question came into play. As said before, a friend pointed out that System.Windows.Forms.Form implements a base class that is abstract. We were able to find...


  • 继承层次结构:

    • Inheritance Hierarchy:


      • System.Object的

        • System.MarshalByRefObject公共** **抽象类MarshalByRefObject的

          • System.ComponentModel.Component

            • System.Windows.Forms.Control

              • System.Windows.Forms.ScrollableControl

                • System.Windows.Forms.ContainerControl

                  • System.Windows.Forms.Form

                    • System.Object
                      • System.MarshalByRefObject (public **abstract** class MarshalByRefObject)
                        • System.ComponentModel.Component
                          • System.Windows.Forms.Control
                            • System.Windows.Forms.ScrollableControl
                              • System.Windows.Forms.ContainerControl
                                • System.Windows.Forms.Form
                                • public class Form1 : MiddleClass
                                  ...
                                  public class MiddleClass : BaseForm
                                  ... 
                                  public abstract class BaseForm : Form
                                  ... 
                                  

                                  这实际工作和设计使得它很好,问题解决了....除非你在生产中的应用具有继承额外级别的,这是因为在设计师的WinForms的不足之处仅在必要!

                                  This actually works and the designer renders it fine, problem solved.... except you have an extra level of inheritance in your production application that was only necessary because of an inadequacy in the winforms designer!

                                  这是不是一个100%万无一失的解决方案,但它的pretty不错。基本上你使用#如果DEBUG 拿出成品的解决方案。

                                  This isn't a 100% surefire solution but its pretty good. Basically you use #if DEBUG to come up with the refined solution.

                                  Form1.cs的

                                  #if DEBUG
                                  public class Form1 : MiddleClass
                                  #else 
                                  public class Form1 : BaseForm
                                  #endif
                                  ...
                                  

                                  MiddleClass.cs

                                  MiddleClass.cs

                                  public class MiddleClass : BaseForm
                                  ... 
                                  

                                  BaseForm.cs

                                  BaseForm.cs

                                  public abstract class BaseForm : Form
                                  ... 
                                  

                                  这样做是只使用初步解决方案中所列的解决方案,如果是在调试模式。我们的想法是,你永远不会通过调试版本发布生产方式和你将永远在调试模式设计。

                                  What this does is only use the solution outlined in "initial solution", if it is in debug mode. The idea is that you will never release production mode via a debug build and that you will always design in debug mode.

                                  这位设计师将始终运行对建在当前模式下的code,所以你不能在发布模式使用设计。但是,只要你在调试模式设计和发布建于发布模式code,你是好去。

                                  The designer will always run against the code built in the current mode, so you cannot use the designer in release mode. However, as long as you design in debug mode and release the code built in release mode, you are good to go.

                                  唯一的万无一失的解决办法是,如果你可以通过preprocessor指令测试设计模式。

                                  The only surefire solution would be if you can test for design mode via a preprocessor directive.

                                  这篇关于我怎样才能获得Visual Studio 2008的Windows窗体设计来呈现,实现一个抽象基类的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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