这里我的代码表继承应该是抽象的
GeneralLesson.cs:这只是一个cs文件,没有了.Designer.cs或.resx文件
public /*abstract*/ class GeneralLesson : Form
{
public GeneralLesson()
{
this.StartPosition = SS.FrmStartPos;//If I want to change it later, I just change it here and all the children will get the change
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (e.CloseReason == CloseReason.WindowsShutDown) return;
SS.LearningDay = 0; //SS is my static class that hold the static variables.
SS.FrmMain.Show();
}
}
SentLesson.cs:这实际上是一个窗口形式,具有了.Designer.cs和.resx文件
public partial class _Sent_Lesson : GeneralLesson
{
public _Sent_Lesson()
{
InitializeComponent();
richTextBox1.Text = "under construction";
}
}
所以它实际上成为我的目的很好。我的SentLesson窗口继承了GeneralLesson的构造函数和OnFormClosing。但问题是我无法再设计我的SentLesson窗口,它显示如下图:
也许我做错了。但我不想创建GeneralLesson作为窗口,因为我没有设计任何控件,我只是想重写一些函数,如OnFormClosing或构造函数。有没有什么办法可以做到这一点,而不需要将GeneralLesson作为一个窗口。
感谢您的阅读。
'SS'是什么?抛出异常的细节是什么?你的问题标题是“应该是抽象的”,但在你的问题中我没有看到任何“抽象”类型。请注意,'抽象'类型不能用于WinForms设计器。 – Dai
@Dai SS是我的静态类,它包含静态变量。我在我的代码中评论它。 开始时,我将普通课程创建为“公共抽象类GeneralLesson:Form”,但之后我将其更改为“公共类GeneralLesson:Form” - 同样的事情,仍然得到Error页面。并且抛出的异常不是来自我的代码,而是因为Visual Studio无法加载Designer。 – 123iamking