【问题标题】:How to make a class or DLL I created appear on VS toolbox如何使我创建的类或 DLL 出现在 VS 工具箱中
【发布时间】:2018-01-08 12:36:01
【问题描述】:

我知道,一旦您构建了 UserControl,它就会自动出现在 Visual Studio 的工具箱中,因此您可以随时拖放它。但是如何在非可视类(如 BackgroundWorker 或 Timer)上做到这一点?

我创建了一个具有属性并引发事件的类(称为 StationMonitor)。我正在与我的同事分享它,我们想通过消除对象的编程实例化来消磨时间。基本上,我们希望这个 StationMonitor 可以从诸如 BackgroundWoker 和 Timer 之类的工具箱中拖放。

我猜有类似下面的事情要做(如果我错了,请纠正我)

    [Something From Visual Studio="Something" version yada yada]
    public class StationMonitor {
       // everything here
    }

【问题讨论】:

  • 当我将 Timer 子类化时,它也会出现在 ToolBox 中。

标签: c# visual-studio class drag-and-drop com-object


【解决方案1】:

要在工具箱中包含一个非可视类,您需要从 Component 派生它

using System.ComponentModel;
...   

class StationMonitor : Component
{
   ...   
   ...   
}

或者,如果您不能从一个类派生,因为您已经继承了另一个类,请实现 IComponent interface,这当然有点乏味..

Interesting reads here.

【讨论】:

  • 谢谢 Taw!我将不得不将此标记为答案。救生员。但是,我想说这阻止了我的课程可序列化。我无法再将 StationMonitor 的对象实例保存到我的 HDD。 :'(
  • 嗯,很有趣。我确信它可以解决,但不能说如何解决。这可能需要一个单独的问题,imo。首先看看this interesting answer, though!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
相关资源
最近更新 更多