从Visual Studio 2008的WinForms工具箱中过滤自定义.net控件有哪些选择?

时间:2022-02-04 15:50:26

Visual Studio 2008 does a much better job of detecting and adding controls from projects to the toolbox for use in the forms designer. If you have an assembly with a UserControl- or DataSet-derived type, then it will automatically detect and add that control to the toolbox for designing forms. This is slightly better than the old system in 2005 that made you manually add controls and would occasionally forget them, etc.

Visual Studio 2008可以更好地检测项目中的控件并将其添加到工具箱中,以便在表单设计器中使用。如果您有一个具有UserControl或DataSet派生类型的程序集,那么它将自动检测并将该控件添加到工具箱以设计表单。这比2005年的旧系统稍微好一点,它使您手动添加控件,偶尔会忘记它们等。

However, on the legacy, monolithic project I am working on (now upgraded to vs2008) this means many controls that I don't want and don't need (and a redesign would not be warranted against so much legacy code :( ). I imagine that if I made certain types internal or private, then they wouldn't show up. However, I need many of those to remain public, but not show up in the toolbox. Furthermore, with so many controls getting added to the toolbox, opening the winforms designer slows significantly.

然而,在我正在研究的遗留的单片项目(现在升级到vs2008)上,这意味着我不想要和不需要的许多控件(并且不需要重新设计这么多遗留代码:()。我想如果我将某些类型设置为内部或私有,那么它们就不会显示出来。但是,我需要很多这些类型保持公开,但不会显示在工具箱中。此外,有这么多控件被添加到工具箱中打开winforms设计师的速度明显放缓。

  1. Is there an attribute or other mechanism that prevents toolbox appearance (that wouldn't otherwise affect functionality) ?
  2. 是否存在阻止工具箱外观的属性或其他机制(否则会影响功能)?

  3. Would filtering using such a mechanism improve performance while still autodetecting new types that SHOULD be in the toolbox? (I know you can disable the autodetect, but its nice to have in many cases)
  4. 使用这种机制进行过滤是否会提高性能,同时仍然自动检测应该位于工具箱中的新类型? (我知道你可以禁用自动检测,但在许多情况下很好)

  5. Have others encountered this irritation on large solutions (with many csproj/vbproj files)?
  6. 让其他人在大型解决方案上遇到这种烦恼(使用许多csproj / vbproj文件)?

Edit: Thanks everyone! I knew it had to be simple (and was likely an attribute) but that fills the gap. Nice to know that I was in good company in not knowing about ToolBoxItem(false).

编辑:谢谢大家!我知道它必须简单(并且可能是一个属性),但这填补了空白。很高兴知道我在不了解ToolBoxItem(错误)方面做得很好。

2 个解决方案

#1


The following attribute should hide it from the toolbox:

以下属性应将其从工具箱中隐藏:

[ToolboxItem(false)]

If you apply it to all the types you don't want to show, it will still show any new ones you create without this attribute. Note, you may have to manually remove the items to start with.

如果将其应用于您不想显示的所有类型,它仍将显示您在没有此属性的情况下创建的任何新类型。请注意,您可能必须手动删除要开始的项目。

This blog post shows some other attributes you may want to use.

此博客文章显示了您可能想要使用的其他一些属性。

#2


Go through the toolbox and for each custom control that you see that you want to hide, add the following attribute above the class:

浏览工具箱,对于您看到要隐藏的每个自定义控件,在类上方添加以下属性:

[ToolboxItem(false)]

Of course, this is a compiled attribute and will affect everyone using the code, so I only recommend doing this for controls that don't make drag-drop sense. Otherwise, you will probably make someone that loves that control very very angry. :)

当然,这是一个已编译的属性,会影响使用该代码的每个人,因此我建议对不具有拖放感的控件执行此操作。否则,你可能会让喜欢那种控制的人非常生气。 :)

#1


The following attribute should hide it from the toolbox:

以下属性应将其从工具箱中隐藏:

[ToolboxItem(false)]

If you apply it to all the types you don't want to show, it will still show any new ones you create without this attribute. Note, you may have to manually remove the items to start with.

如果将其应用于您不想显示的所有类型,它仍将显示您在没有此属性的情况下创建的任何新类型。请注意,您可能必须手动删除要开始的项目。

This blog post shows some other attributes you may want to use.

此博客文章显示了您可能想要使用的其他一些属性。

#2


Go through the toolbox and for each custom control that you see that you want to hide, add the following attribute above the class:

浏览工具箱,对于您看到要隐藏的每个自定义控件,在类上方添加以下属性:

[ToolboxItem(false)]

Of course, this is a compiled attribute and will affect everyone using the code, so I only recommend doing this for controls that don't make drag-drop sense. Otherwise, you will probably make someone that loves that control very very angry. :)

当然,这是一个已编译的属性,会影响使用该代码的每个人,因此我建议对不具有拖放感的控件执行此操作。否则,你可能会让喜欢那种控制的人非常生气。 :)