3
我試圖在WinForms應用程序中實現與ASP.NET主窗體一樣的類似效果。我最初的想法是創建一個基本表單並將其聲明爲抽象,但編譯器似乎不讓我這樣做。使用WinForms的抽象窗體
public abstract partial class Master : Form
{
public Master()
{
InitializeComponent();
}
}
所以我有兩個問題:
- 爲什麼編譯器不會讓我這樣做呢?我是否使用了錯誤的語法,或者這是一個真正的限制。
- 任何人都可以提出一種解決方法或更好的方法來做到這一點?
編輯:
的InitializeComponent代碼:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.Menu = this.mainMenu1;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.Text = "Master";
this.AutoScroll = true;
}
編輯:
錯誤如下:
The designer must create an instance of type 'Namespace.Master' but it cannot because the type is declared as abstract.
實際的編譯器錯誤是什麼? – 2011-01-14 15:33:09
如果這是你試圖編譯的確切代碼片段,你需要爲InitializeComponent()提供一個定義 – asawyer 2011-01-14 15:35:28