ToolboxDataAttribute 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定当从 Microsoft Visual Studio 等工具中的工具箱拖动自定义控件时为它生成的默认标记。
public ref class ToolboxDataAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class ToolboxDataAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.Class)>]
type ToolboxDataAttribute = class
    inherit AttributePublic NotInheritable Class ToolboxDataAttribute
Inherits Attribute- 继承
- 属性
示例
[ ToolboxData("<{0}:MyLabel runat= server Text=   
       MyLabel><{0}:MyLabel>") ]public class MyLabel : Label {...}  
在下面的代码示例中,前面的代码设置多个特定于 MyLabel的属性。 设计器会将 的所有 {0} 匹配项替换为与 类关联的 MyLabel 标记前缀。
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomControls
{
  [ ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10'  runat='server'></{0}:MyLabel>") ]	
  public class MyLabel : Label 
  {
    public  MyLabel()
    { 
      // Your code goes here.
    } 
  }
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace CustomControls
  <ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' BackColor='Magenta' BorderWidth = '10'  runat='server'></{0}:MyLabel>")>  _
  Public Class MyLabel
    Inherits Label
     
    Public Sub New()
      'Your code goes here.
    End Sub
    
  End Class
  
End Namespace 'CustomControls
注解
默认情况下,Visual Studio 等工具的可视化设计器会创建一个空标记。 当控件从可视设计器的工具箱拖放到设计图面上时,这是表示处于其默认状态的控件的标记。 若要指定初始默认值,控件可以使用此属性。 可以使用此属性自定义在控件从工具箱拖到窗体上时放置在设计器中的初始 HTML 内容。
构造函数
| ToolboxDataAttribute(String) | 初始化 ToolboxDataAttribute 类的新实例。 | 
字段
| Default | 表示自定义控件的默认 ToolboxDataAttribute 值。 | 
属性
| Data | 获取表示控件属性初始值的字符串,该字符串用于在可视化设计器中创建该控件的实例。 | 
| TypeId | 在派生类中实现时,获取此 Attribute 的唯一标识符。(继承自 Attribute) | 
方法
| Equals(Object) | 测试 ToolboxDataAttribute 对象是否等于给定对象。 | 
| GetHashCode() | 返回自定义控件的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 测试 ToolboxDataAttribute 对象是否包含 Data 属性的默认值。 | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |