次の方法で共有


BaseValidatorDesigner.GetDesignTimeHtml メソッド

定義

デザイン時に関連付けられたコントロールを描画するために使用するマークアップを取得します。

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

戻り値

デザイン時に BaseValidator を表示するためのマークアップを格納している文字列。

次のコード例は、コントロールの プロパティのGetDesignTimeHtml値が または None フィールドに設定されている場合に、デザイン時に関連付けられたコントロールのBorderStyle周囲に実線の境界線を描画するメソッドをオーバーライドする方法をNotSet示しています。

// Make the full extent of the control more visible in the designer.
// If the border style is None or NotSet, change the border to a 
// solid line. 
public override string GetDesignTimeHtml()
{
    // Get a reference to the control or a copy of the control.
    SimpleCompareValidator myCV = (SimpleCompareValidator)ViewControl;
    string markup = null;

    // Check if the border style should be changed.
    if (myCV.BorderStyle == BorderStyle.NotSet ||
        myCV.BorderStyle == BorderStyle.None)
    {
        // Save the current property setting.
        BorderStyle oldBorderStyle = myCV.BorderStyle;

        // Set the design-time property and catch any exceptions.
        try
        {
            myCV.BorderStyle = BorderStyle.Solid;

            // Call the base method to generate the markup.
            markup = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // Restore the property to its original setting.
            myCV.BorderStyle = oldBorderStyle;
        }
    }
    else
    {
        // Call the base method to generate the markup.
        markup = base.GetDesignTimeHtml();
    }

    return markup;
} // GetDesignTimeHtml
' Make the full extent of the control more visible in the designer.
' If the border style is None or NotSet, change the border to a 
' solid line. 
Public Overrides Function GetDesignTimeHtml() As String

    ' Get a reference to the control or a copy of the control.
    Dim myCV As SimpleCompareValidator = _
        CType(ViewControl, SimpleCompareValidator)
    Dim markup As String

    ' Check if the border style should be changed.
    If (myCV.BorderStyle = BorderStyle.NotSet Or _
        myCV.BorderStyle = BorderStyle.None) Then

        ' Save the current property setting.
        Dim oldBorderStyle As BorderStyle = myCV.BorderStyle

        ' Set the design-time property and catch any exceptions.
        Try
            myCV.BorderStyle = BorderStyle.Solid

            ' Call the base method to generate the markup.
            markup = MyBase.GetDesignTimeHtml()

        Catch ex As Exception
            markup = GetErrorDesignTimeHtml(ex)

        Finally
            ' Restore the property to its original setting.
            myCV.BorderStyle = oldBorderStyle
        End Try

    Else
        ' Call the base method to generate the markup.
        markup = MyBase.GetDesignTimeHtml()
    End If

    Return markup
End Function

注釈

ErrorMessageクラスからBaseValidator派生した関連付けられたコントロールの または Text プロパティが空の文字列 ("") の場合、または プロパティが フィールドにNone設定されている場合DisplayGetDesignTimeHtmlメソッドは プロパティをコントロール ID に設定ErrorMessageします。このプロパティは角かっこ ([]) で囲んでフィールドにStatic設定Displayされます。 GetDesignTimeHtml次に、基本メソッドをGetDesignTimeHtml呼び出してマークアップを生成し、必要に応じてコントロール プロパティを元の値に復元します。

適用対象

こちらもご覧ください