C# - 标记自定义表单的基类使设计视图显示 HTML
好吧。我有一个带有多个对话框的应用程序,其中有一些事件,它们都以相同的方式响应,并且都有一些提供给演示者的方法。这些都已被推入 a:
public abstract class BaseFormClass : Form
中,所有其他形式是:
public class DerivedFormClass : BaseFormClass
我已经进行了模型-视图-呈现器设置,因此基类有一些受保护的 EventHandler
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 设置它自己的处理程序函数来处理任何必要的清理或任何必要的操作。
既然背景故事已经完成,主要问题是,为什么当我进行将父表单标记为抽象的简单更改时,我的子表单的设计视图会偏离正常的设计视图只是吐出一堆乱七八糟的 HTML(好吧,不是乱七八糟,一行看起来像是表单的整个 HTML...)?
谁能建议我可能做错了什么?
Alright so. I have an app with several dialogs that have a handful of events that they all respond the same way to, and all have a few methods they provide to the Presenter. These have all been pushed up into a:
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;
Then the presenter uses the OnFormClose setter to set it's own handler function to handle any necessary cleanups or whatever's necessary.
Now that the backstory is out of the way, the main question is, why when I make the simple change of marking the parent Form as abstract does my design view of my child Forms go from the normal design view to just spitting out a mess of HTML (well, not a mess, a single line of what appears to be the entire HTML of the form...)?
Can anyone suggest what I might be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前从未尝试过此操作,但在 Visual Studio 2010 中尝试相同的操作时,出现错误
设计器必须创建类型为“WinFormsTestApp.FormA”的实例,但它不能,因为该类型被声明为抽象。
我怀疑这正是它所说的意思 - 为了显示您的派生形式,出于某种已知的原因仅对于其自身,设计者需要创建父窗体的实例,但显然不能这样做。抱歉,您可能需要重新设计您的层次结构。 VS 设计者对用于表单和控件的继承模式做出了很多假设,因此如果偏离标准模式,这些问题很常见。
I have never tried this before, but trying the same in Visual Studio 2010, I get the error
The designer must create an instance of type 'WinFormsTestApp.FormA' but it cannot because the type is declared as abstract.
I suspect this means exactly what it says - in order to display your derived form, for some reason known only to itself, the designer needs to create an instance of the parent form, and obviously can't do that. Sorry, but you will probably have to redesign your hierarchy. The VS designers make a lot of assumptions about the inheritance patterns used for forms and controls, so if you stray from the standard patterns, these problems are quite common.