VS2010:使用继承的用户控件时如何避免Windows Forms设计器问题? [英] VS2010: How to avoid Windows Forms designer problems when working with inherited user controls?

查看:147
本文介绍了VS2010:使用继承的用户控件时如何避免Windows Forms设计器问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:当基类从另一个程序集实现接口时,Windows Forms设计器不适用于继承的用户控件。

Problem: The Windows Forms designer does not work for an inherited user control when the base class is implementing an interface from another assembly.

平台:VS 2010 SP1, .NET 4.0框架

Platform: VS 2010 SP1, .NET 4.0 Framework

错误:


无法显示设计器
此文件,因为其中的任何类
都无法设计。
设计者检查了文件中的以下
类:MyControl ---
基类
‘MyBaseControlLib.MyBaseControl’无法加载
。确保程序集已引用
,并且已构建所有项目

The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: MyControl --- The base class 'MyBaseControlLib.MyBaseControl' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

位于
,位于System.ComponentModel.Design.Serialization。 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
manager)at
上的CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager
manager) VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager
serializationManager)at
Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32
f / p>

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)

我有3个类库项目的解决方案:

I have a solution with 3 class library projects:

MyInterfaceLib:

MyInterfaceLib:

namespace MyInterfaceLib
{
    public interface IMyInterface
    {
        void Foo();
    }
}

MyBaseControlLib:

MyBaseControlLib:

namespace MyBaseControlLib
{
    using System.Windows.Forms;
    using MyInterfaceLib;

    public partial class MyBaseControl : UserControl, IMyInterface
    {
        public MyBaseControl()
        {
            InitializeComponent();
        }

        public void Foo()
        {
        }
    }
}

MyDerivedLib:

MyDerivedLib:

namespace MyDerivedControlLib
{
    using MyBaseControlLib;

    public partial class MyControl : MyBaseControl
    {
        public MyControl()
        {
            InitializeComponent();
        }
    }
}

尽管设计器适用于MyBaseControl它不适用于MyControl。
如果MyBaseControl不实现IMyInterface,则设计器也可以使用MyControl。

Although the designer works for MyBaseControl it does not work for MyControl. If MyBaseControl does not implement IMyInterface, the designer also works for MyControl.

有什么想法吗?

感谢
罗伯特

推荐答案

我们遇到了同样的问题。

We had the same issue. We used a workarround by creating a MyControlDesign class that is inherited by MyControl class.

 public partial class MyControl : MyControlDesign {
   public MyControl()
  {
      InitializeComponent();
  }
}

public partial class MyControlDesign : MyBaseControl
{
  public MyControlDesign ():base()
  {
  }
}

这篇关于VS2010:使用继承的用户控件时如何避免Windows Forms设计器问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆