ToolboxDataAttribute 类


指定当从 Microsoft Visual Studio 等工具中的工具箱拖动自定义控件时为它生成的默认标记。Specifies the default tag generated for a custom control when it is dragged from a toolbox in a tool such as Microsoft Visual Studio.

public ref class ToolboxDataAttribute sealed : Attribute
public sealed class ToolboxDataAttribute : Attribute
type ToolboxDataAttribute = class
    inherit Attribute
Public NotInheritable Class ToolboxDataAttribute
Inherits Attribute


[ ToolboxData("<{0}:MyLabel runat= server Text=   
       MyLabel><{0}:MyLabel>") ]public class MyLabel : Label {...}  

在下面的代码示例中, 前面的代码将设置特定于MyLabel的几个属性。In the following code example, the previous code sets several properties specific to MyLabel. 所有出现的{0}都由设计器替换为与MyLabel类关联的标记前缀。All occurrences of {0} are replaced, by the designer, with the tag prefix associated with the MyLabel class.

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 等工具的可视化设计器会创建一个空标记。By default, the visual designer of a tool such as Visual Studio, creates an empty tag. 当控件从可视化设计器的工具箱拖到设计图面上时, 此标记表示处于默认状态的控件。This is a tag representing a control in its default state, when the control is dropped from the toolbox of a visual designer onto the design surface. 若要指定初始默认值, 控件可以使用此特性。To specify initial default values, a control can make use of this attribute. 将控件从 "工具箱" 拖到窗体上时, 可以使用此特性自定义放置在设计器中的初始 HTML 内容。You can use this attribute to customize the initial HTML content that is placed in the designer when the control is dragged from the toolbox onto the form.



初始化 ToolboxDataAttribute 类的新实例。Initializes a new instance of the ToolboxDataAttribute class.



表示自定义控件的默认 ToolboxDataAttribute 值。Represents the default ToolboxDataAttribute value for a custom control.



获取表示控件属性初始值的字符串,该字符串用于在可视化设计器中创建该控件的实例。Gets the string representing the initial values of the control's property, which is used in a visual designer for creating an instance of the control.


在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)



测试 ToolboxDataAttribute 对象是否等于给定对象。Tests whether the ToolboxDataAttribute object is equal to the given object.


返回自定义控件的哈希代码。Returns the hash code of the custom control.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

测试 ToolboxDataAttribute 对象是否包含 Data 属性的默认值。Tests whether the ToolboxDataAttribute object contains the default value for the Data property.


当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)


_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)