這裏我的代碼表繼承應該是抽象的
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