我正在尝试在 WinForms 应用程序中实现与主窗体在 ASP.NET 中所做的类似的效果。我最初的想法是创建一个基本形式并将其声明为抽象形式,但编译器似乎不允许我这样做。
public abstract partial class Master : Form
{
public Master()
{
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.
最佳答案
I’m trying to achieve a similar affect in a WinForms application as a master form does with ASP.NET.
Winforms 并没有真正的母版页的概念。我认为您最好的选择是使用 UserControl,并嵌套您的 UI 组合。
也许可以实现一个简单的接口(interface),比如让访问子控件更容易一些。
public interface IMasterPage
{
IControlContainer Container { get; }
}
只是一些想法,祝你的项目好运。
关于c# - 使用 WinForms 抽象表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692704/