ToolboxDataAttribute 類別

定義

指定當自訂控制項從工具 (例如 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 Attribute
Public NotInheritable Class ToolboxDataAttribute
Inherits Attribute
繼承
ToolboxDataAttribute
屬性

範例

[ 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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱