ButtonDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


ビジュアルなデザイナでソース ビューからデザイン ビューに切り替えると、Button コントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時コントロールがマークアップのソース コードに永続化され、Web ページのマークアップに反映されます。

このセクションには、2 つのコード例が用意されています。最初のコード例は、ButtonDesigner クラスを拡張する方法を示しています。2 番目のコード例は、Button クラスを拡張して、最初のコード例で作成したクラスに関連付ける方法を示しています。
ButtonDesigner クラスを拡張して、GetDesignTimeHtml メソッドをオーバーライドするカスタム デザイナ クラスを作成する方法を次のコード例に示します。BorderStyle プロパティがまだ設定されていない (つまり、NotSet フィールド値がない) 場合、GetDesignTimeHtml メソッドを呼び出すと、このプロパティが幅 3 ピクセルの青い点線の境界線に設定され、その境界線がデザイン サーフェイスに表示されます。BorderStyle プロパティに値が既に設定されている場合は、既存の境界線プロパティの値が表示されます。
通常、GetDesignTimeHtml は、その基本メソッドである ControlDesigner.GetDesignTimeHtml を呼び出します。この基本メソッドは、関連付けられたコントロールの Control.RenderControl メソッドを呼び出して、マークアップを生成します。
' Create a class that derives from ButtonDesigner ' and displays the custom SampleButton control ' on the design surface. Imports System Imports System.Web.UI.Design Imports System.Drawing Imports System.ComponentModel Imports System.Web.UI.WebControls Imports System.Web.UI.Design.WebControls Namespace Examples.AspNet Public Class SampleButtonDesigner Inherits ButtonDesigner ' Override the GetDesignTimeHtml method. Public Overrides Function GetDesignTimeHtml() As String Dim sampleButton As SampleButton = CType(Component, SampleButton) Dim designTimeHtml As String = Nothing ' Check the control's BorderStyle property ' to conditionally render design-time HTML. If (sampleButton.BorderStyle = BorderStyle.NotSet) Then ' Create variables to hold current property settings. Dim oldBorderStyle As BorderStyle = sampleButton.BorderStyle Dim oldBorderWidth As Unit = sampleButton.BorderWidth Dim oldBorderColor As Color = sampleButton.BorderColor ' Set properties and the design-time HTML. Try sampleButton.BorderStyle = BorderStyle.Dashed sampleButton.BorderWidth = Unit.Pixel(3) sampleButton.BorderColor = Color.Blue designTimeHtml = MyBase.GetDesignTimeHtml() ' If an exception occurs, call the GetErrorDesignTimeHtml ' method. Catch ex As Exception designTimeHtml = GetErrorDesignTimeHtml(ex) ' Return properties to their original settings. Finally sampleButton.BorderStyle = oldBorderStyle sampleButton.BorderWidth = oldBorderWidth sampleButton.BorderColor = oldBorderColor End Try Else designTimeHtml = MyBase.GetDesignTimeHtml() End If Return designTimeHtml End Function End Class End Namespace
Button クラスを拡張し、上記の例で作成した SampleButtonDesigner クラスに DesignerAttribute オブジェクトを使用して関連付ける単純なクラスの使用方法を次のコード例に示します。


System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.WebControls.ButtonDesigner


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からButtonDesigner クラスを検索する場合は、下記のリンクをクリックしてください。

- ButtonDesigner クラスのページへのリンク