开发者

Abstract Forms using WinForms

开发者 https://www.devze.com 2023-02-04 14:29 出处:网络
I’m trying to achieve a similar affect in a WinForms application as a master form does with ASP.NET.My initial thoughts on this were to create a base form and declare it as abstract, but the compiler

I’m trying to achieve a similar affect in a WinForms application as a master form does with ASP.NET. My initial thoughts on this were to create a base form and declare it as abstract, but the compiler doesn’t seem to let me do this.

public abstract partial class Master : Form
{
    public Master()
    {
        InitializeComponent();
    }
}

So I have two questions:

  • Why will the compiler not let me do this? Am I using the wrong syntax or is this a genuine restriction.
  • Can anyone suggest a workaround or better way to do this?

EDIT:

InitializeComponent code:

    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.mainMenu1 = new System.Windows.Forms.MainMenu();
        this.Menu = this.mainMenu1;
        this.AutoScaleMode = System.Windows.开发者_如何学CForms.AutoScaleMode.Dpi;
        this.Text = "Master";
        this.AutoScroll = true;
    }

EDIT:

The error is as follows:

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 doesn't really have the concept of a master page. I imagine your best bet is to use UserControls, and nest your UI composition.

Maybe implement a simple interface like something like to make accessing the sub controls a little easier.

public interface IMasterPage
{
 IControlContainer Container { get; }
}

Just some thoughts, good luck with your project.

0

精彩评论

暂无评论...
验证码 换一张
取 消