次の方法で共有


CheckBoxDesigner.GetDesignTimeHtml メソッド

定義

デザイン時にコントロールを表すために使用するマークアップを取得します。

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String

戻り値

String

デザイン時にコントロールを表すために使用するマークアップ。

次のコード例では、メソッドを GetDesignTimeHtml オーバーライドします。 プロパティが CheckBox.Text 以前に設定されていない場合、このメソッドの呼び出しによって文字列が設定され、その文字列がデザイン画面に表示されます。 プロパティが既に Text 設定されている場合は、既存のプロパティ値が表示されます。

' Override the GetDesignTimeHtml method to display a border on the 
' control if the BorderStyle property has not been set by the user.
Public Overrides Function GetDesignTimeHtml() As String

    Dim sampleCheckBox As SampleCheckBox = CType(Component, _
        SampleCheckBox)
    Dim designTimeHtml As String = Nothing

    ' Check the control's BorderStyle property.
    If (sampleCheckBox.BorderStyle = BorderStyle.NotSet) Then

        ' Save the current value of the BorderStyle property.
        Dim oldBorderStyle As BorderStyle = _
            sampleCheckBox.BorderStyle

        ' Change the value of the BorderStyle property and 
        ' generate 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)

            ' Restore the BorderStyle property to its original value.
        Finally
            sampleCheckBox.BorderStyle = oldBorderStyle
        End Try

    Else
        designTimeHtml = MyBase.GetDesignTimeHtml()
    End If

    Return designTimeHtml
End Function

注釈

Textプロパティが空の場合、または空白のみで構成されている場合、生成された HTML にはチェック ボックス コントロールの内容がID含まれます。それ以外の場合、生成された HTML にはコントロールのTextプロパティの内容が含まれます。

生成された HTML を変更するには、このメソッドをオーバーライドします。

適用対象

こちらもご覧ください