デザイナを初期化し、指定されたコンポーネントを読み込みます。
Overrides Public Sub Initialize( _
ByVal component As IComponent _) Implements IDesigner.Initialize
[C#]
public override void Initialize(IComponentcomponent);
[C++]
public: void Initialize(IComponent* component);
[JScript]
public override function Initialize(
component : IComponent);
パラメータ
- component
デザイン対象のコントロール要素。
実装
解説
このメソッドは、デザイナ ホストによって呼び出され、コンポーネントをデザイナに読み込みます。
使用例
[Visual Basic] Initialize メソッドをオーバーライドして、デザイナと関連付けられているコントロールが Simple という名前のカスタム クラスのインスタンスであることを検証するクラスのコード例を次に示します。Simple のインスタンスでない場合は、 ArgumentException がスローされます。
' Create a designer class for a custom class,
' named Simple.
Imports System
Imports System.ComponentModel
Imports System.IO
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Imports AspNet.Samples
Namespace AspNet.Samples.Design
Public Class SimpleDesigner
Inherits System.Web.UI.Design.ControlDesigner
' Declare a reference to the Simple class
Private simpleControl As Simple
' Create a constructor for the designer class
' When an instance of the designer is created,
' the Text property of the instance of a Simple control
' is set to the designer's ID property.
' the designer is called.
Public Sub New()
simpleControl = CType(Component, Simple)
simpleControl.Text = Me.ID
End Sub
Overrides Public ReadOnly Property AllowResize As Boolean
Get
Return True
End Get
End Property
Public Overrides Function GetDesignTimeHtml() As String
' Component is the instance of the component or control that
' this designer object is associated with. This property is
' inherited from System.ComponentModel.ComponentDesigner.
simpleControl = CType(Component, Simple)
If simpleControl.Text.Length > 0 Then
Dim sw As New StringWriter()
Dim tw As New HtmlTextWriter(sw)
Dim placeholderLink As New HyperLink()
' Put simpleControl.Text into the link's Text.
placeholderLink.Text = simpleControl.Text
placeholderLink.href = simpleControl.Text
placeholderLink.RenderControl(tw)
Return sw.ToString()
Else
Return GetEmptyDesignTimeHtml()
End If
End Function
' Override the OnControlResize method to
' set the IsDirty property to true and
' call the UpdateDesignTimeHtml method.
Overrides Protected Sub OnControlResize()
Me.IsDirty = True
Me.UpdateDesignTimeHtml
End Sub
' Override the Initialize method to ensure
' that the designer is always working with
' an instance of the Simple class.
Overrides Public Sub Initialize( _
ByVal component As IComponent _
)
If Not (component Is simpleControl)
throw new ArgumentException( _
"The component must be an instance of the Simple class.", _
"component")
End If
MyBase.Initialize(component)
End Sub
End Class
End Namespace
[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- 直前の呼び出し元の完全信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細の参照先 : 部分信頼コードからのライブラリの使用
参照
ControlDesigner クラス | ControlDesigner メンバ | System.Web.UI.Design 名前空間 | IDesigner