好吧。我有一个带有多个对话框的应用程序,这些对话框有一些事件,它们都以相同的方式响应,并且都有一些方法提供给 Presenter。这些都被推到了一个:
public abstract class BaseFormClass : Form
and all the other forms are:
public class DerivedFormClass : BaseFormClass
I've got a model-view-presenter setup going, so the base class has a few protected EventHandler<EventArgs>, and for each one is a similarly named function which is assigned to be called for that event, and a setter exists that the presenter can assign it's own function to be used as the handler for the event. (In other words:)
protected void OnFormBeginClosing(object sender, FormClosingEventArgs e)
{
if (formClosing == null)
return;
formClosing(sender, e);
}
public EventHandler OnFormClose
{
set
{
formClosing = value;
}
}
protected EventHander<EventArgs> formClosing;
然后演示者使用 OnFormClose setter 设置它自己的处理函数来处理任何必要的清理或任何必要的事情。
现在背景故事已经讲完了,主要问题是,为什么当我将父 Form 标记为抽象的简单更改时,我的子 Forms 的设计 View 却从正常的设计 View 只是吐出一堆 HTML(好吧,不是一团糟,一行似乎是表单的整个 HTML...)?
任何人都可以建议我可能做错了什么吗?
最佳答案
我以前从未尝试过,但在 Visual Studio 2010 中尝试相同时,我收到错误 设计器必须创建类型为“WinFormsTestApp.FormA”的实例,但它不能创建,因为该类型被声明为抽象类型。
我怀疑这就是它所说的意思 - 为了显示您的派生表单,出于某种只有它自己知道的原因,设计者需要创建父表单的实例,但显然不能这样做。抱歉,您可能需要重新设计层次结构。 VS 设计者对用于窗体和控件的继承模式做了很多假设,因此如果您偏离标准模式,这些问题就很常见。
关于C# - 标记自定义窗体的基类使设计 View 显示 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5542602/