What's the state of play with “Visual Inheritance”

后端 未结 6 1311
-上瘾入骨i
-上瘾入骨i 2021-01-05 02:27

We have an application that has to be flexible in how it displays it\'s main form to the user - depending on the user, the form should be slightly different, maybe an extra

6条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 03:01

    I think I've found a way how to avoid this problem.

    Don't hook the Form_Load Event in your parent form, this will break the designer.

    Also don't take the Default empty constructor away from Visual Studio in the Parent Form. If you want to have Dependency Injection, create another constructor.

    Like this:

    public ProductDetail()
    {
        InitializeComponent();
    }
    
    public ProductDetail(ISupplierController supplierController) : base()
    {
        InitializeComponent();
        this.supplierController = supplierController;
    }
    

    You can then still do this from your inherited Form:

    public NewProduct(ISupplierController supplierController)
        : base(supplierController)
    {
        InitializeComponent();
    }
    

    This worked for me so far, and I had some weird designer issues too.

    cheers, Daniel

提交回复
热议问题