我的用户控件没有出现在工具箱中

时间:2013-01-06 06:44:45

标签: c# controls

我有一些用户控件的程序,但是当我构建解决方案时,用户控件不会出现在工具箱上,因为测试我做了另一个用户控件,重新构建后它出现在工具箱上!这是我的一个用户控件:

 using System.Drawing;
using System.Windows.Forms;

namespace AMIgo
{
  /// <summary>A UserControl used to display and interact with the active calls.</summary>
  /// <remarks>This display reflect the content of the <see cref="AMI_Client.AstCallsList"/> which contains the current active calls.
  /// The ListViewCalls display allows to show the items in differents layouts, in a similar way than the windows file explorer.
  /// <para>A menu allows to select to display Inbound( show in Red (default), Outbound (shown in blue) and internal (shown in gray) calls.</para>
  /// <para>Properties allows to set the font and colors of the ListView and ListItems</para>
  /// <para>Drag / Drop: You can drag an active call and drop it onto an extension in the <see cref="ListViewLines"/> display to Transfer a 
  /// caller to an extension. You can drag and drop an active call to the display toolbar drop target to Transfer the active channel to the 
  /// selected destination, to park the call or to hang it up. You can also drag an active channel to the <see cref="AMIgoDropTarget"/> form to Transfer a call to the selected destination. 
  /// (Extension, queue, conference, etc)</para>
  /// <para> Context Menu: Right click on an item to open a Context menu.</para>
  /// <seealso cref="AstCall"/><seealso cref="AMI_Client.NewCallEvent"/></remarks>
  [ToolboxBitmap(typeof(AMIgo.ListViewCalls), "Resources.Control_ListView.bmp")]
  public partial class ListViewCalls : AMIgoControl
  {
    /// <summary>Gets or sets a value indicating whether the intermediary agents channels are displayed.</summary>
    /// <value><c>true</c> to show Agents channels otherwise, <c>false</c>.</value>
    public bool ShowAgentsChannels { get; set; }
    private bool _show_outbound_calls;
    /// <summary>Gets or sets a value indicating whether the outbound calls are displayed.</summary>
    /// <value><c>true</c> to show outbound calls, otherwise, <c>false</c>.</value>
    public bool ShowOutboundCalls 
    {
      get { return (_show_outbound_calls); } 
      set 
      {
        _show_outbound_calls = value;
        outboundToolStripMenuItem.Checked = _show_outbound_calls;
      }
    }
    private bool _show_internal_calls;
.
.
.
.
.

这是AMIgoControl文件......

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

namespace AMIgo
{
  /// <summary>
  /// This is the base control from which inherit most of the AMIgo controls
  /// </summary>
  [DesignTimeVisible(false)]
  [System.ComponentModel.ToolboxItem(false)]
  public class AMIgoControl : UserControl
  {
    /// <summary>true after this control has been initialized. </summary>
    public bool _InitDone;
    /// <summary>Gets or sets the AMI_Client instance. The AMI_Client component will set this on startup if left blank.</summary>
    public virtual AMIgo.AMI_Client AMI_ClientInstance { get; set; }
    /// <summary>Initializes a new instance of the <see cref="AMIgoControl"/> class.</summary>
    public AMIgoControl() { }
    /// <summary>Initializes a new instance of the <see cref="AMIgoControl"/> class. </summary>
    /// <param name="AMI_ClientInstance">The AMI_Client instance.</param>
    public AMIgoControl(AMIgo.AMI_Client AMI_ClientInstance)
    {
      this.AMI_ClientInstance = AMI_ClientInstance;
    }
    /// <summary>Finds a Control recursively. Note finds the first match and exits</summary>
    /// <param name="Container">The container to search for the given control type.
    /// Remember all controls (Panel, GroupBox, Form, etc are all containers for controls
    /// </param>
    /// <param name="TypeName">Name of the type of control to look for</param>
    /// <returns>The control object if found or null</returns>
    /// 
    public Control FindControlRecursive(Control Container, string TypeName)
    {
      if (Container.GetType().Name == TypeName)
        return Container;

      foreach (Control ctrl in Container.Controls)
      {
        Control foundCtrl = FindControlRecursive(ctrl, TypeName);
        if (foundCtrl != null)
          return foundCtrl;
      }
      return null;
    }

  } //UserControl

1 个答案:

答案 0 :(得分:3)

仅适用于初学者:VS中的工具箱应用了上下文过滤器,因此除非您在文档中打开并激活了设计器,否则您将看不到用户控件。如果你已经尝试过这个并且仍然没有看到控件 - 你是否可以发布截图以便更好地理解?另外,请提及您正在使用的VS版本 - 我刚尝试在VS12上创建示例UC,它的工作方式与预期一致。也许,您可能也想进行该测试,并将更新与结果一起发布。

更新:顺便说一句,您可能希望删除AMIgo类上的ToolboxItem(false)属性。