次の方法で共有


CheckBoxDesigner クラス

CheckBox Web サーバー コントロールのデザイン時の動作を拡張します。

この型のすべてのメンバの一覧については、CheckBoxDesigner メンバ を参照してください。

System.Object
   System.ComponentModel.Design.ComponentDesigner
      System.Web.UI.Design.HtmlControlDesigner
         System.Web.UI.Design.ControlDesigner
            System.Web.UI.Design.WebControls.CheckBoxDesigner

Public Class CheckBoxDesigner
   Inherits ControlDesigner
[C#]
public class CheckBoxDesigner : ControlDesigner
[C++]
public __gc class CheckBoxDesigner : public ControlDesigner
[JScript]
public class CheckBoxDesigner extends ControlDesigner

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

CheckBoxDesigner クラスは、 ControlDesigner クラスの GetDesignTimeHtml メソッドをオーバーライドして、コントロールの空の Text プロパティをすべて設定し、デザイン時にコントロールがわかりやすく表示されるようにします。 Text プロパティが空の場合、このクラスの GetDesignTimeHtml メソッドは、コントロールの Text プロパティを、そのコントロールの Control.ID プロパティに設定します。

使用例

[Visual Basic] SampleCheckBoxDesigner という名前のカスタム デザイナ クラスを CheckBoxDesigner クラスから継承して作成するコード例を次に示します。このカスタム クラスは GetDesignTimeHtml メソッドをオーバーライドします。 CheckBox.Text プロパティが設定済みでない場合は、このメソッドを呼び出すと、プロパティに文字列が設定され、デザイン画面にその文字列が表示されます。 Text プロパティに値が既に設定されている場合は、その値が表示されます。

 
' Create a class, named SampleCheckBoxDesigner, that 
' overrides the GetDesignTimeHtml method to display
' the control on the design surface.
Imports System
Imports System.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports Examples.AspNet

Namespace Examples.AspNet.Design

        ' Override the GetDesignTimeHtml method to display
        ' display a border on the control if the BorderStyle
        ' property has not been set by the user.
        <System.Security.Permissions.SecurityPermission( _
          System.Security.Permissions.SecurityAction.Demand, _
          Flags := System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
        Public Class SampleCheckBoxDesigner
            Inherits CheckBoxDesigner
        
            ' Override the GetDesignTimeHtml method.
            Public Overrides Function GetDesignTimeHtml() As String

                Dim sampleCheckBox As SampleCheckBox = CType(Component, SampleCheckBox)
                Dim designTimeHtml As String = Nothing
    
                ' Check the control's BorderStyle property
                ' to conditionally render design-time HTML.
                If (sampleCheckBox.BorderStyle = BorderStyle.NotSet) Then

                    ' Create variables to hold current property settings.
                    Dim oldBorderStyle As BorderStyle = sampleCheckBox.BorderStyle
                    
                   ' Set properties and the design-time HTML.
                    Try
                        sampleCheckBox.BorderStyle = BorderStyle.Groove
                    
                        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
                        sampleCheckBox.BorderStyle = oldBorderStyle
                    End Try
          
                Else
                    designTimeHtml = MyBase.GetDesignTimeHtml()
                End If
      
                Return designTimeHTML
            End Function
    End Class
End Namespace

[Visual Basic] SampleCheckBox という名前の単純なクラスを CheckBox クラスから継承して作成するコード例を次に示します。このクラスは、 DesignerAttribute クラスにより SampleCheckBoxDesigner クラスと関連付けられます。

 
' The SampleCheckBox class that uses the 
' SampleCheckBoxDesigner class.
<Designer(GetType( _
Examples.AspNet.Design.SampleCheckBoxDesigner))> _
Public Class SampleCheckBox
 Inherits CheckBox
   ' Include code here for custom
   ' CheckBox class.
End Class

[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.Design.WebControls

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Design (System.Design.dll 内)

参照

CheckBoxDesigner メンバ | System.Web.UI.Design.WebControls 名前空間 | CheckBox