0

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

 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
4

1 回答 1

3

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

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

于 2013-01-06T06:51:58.843 回答