Share via


MenuDesigner.GetDesignTimeHtml 方法

定義

取得在設計階段用來呈現關聯控制項的標記。

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

傳回

字串,包含在設計階段用來呈現 Menu 的標記。

範例

下列程式碼範例示範如何在繼承自 MenuDesigner 類別的類別中覆寫 GetDesignTimeHtml 方法。 覆寫的方法會變更在設計階段衍生自 Menu 控制項的控制面板。 如果控制項的 屬性是 NotSetNone 值,此範例會繪製控制項周圍的橙色虛線框線, BorderStyle 使其範圍更可見。

// Generate the design-time markup.
public override string GetDesignTimeHtml()
{
    // Make the control more visible in the designer.  If the border 
    // style is None or NotSet, change the border to an orange dotted line. 
    MyMenu myMenuCtl = (MyMenu)ViewControl;
    string markup = null;

    // Check if the border style should be changed.
    if (myMenuCtl.BorderStyle == BorderStyle.NotSet ||
        myMenuCtl.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myMenuCtl.BorderStyle;
        Color oldBorderColor = myMenuCtl.BorderColor;

        // Set the design-time properties and catch any exceptions.
        try
        {
            myMenuCtl.BorderStyle = BorderStyle.Dotted;
            myMenuCtl.BorderColor = Color.FromArgb(0xFF7F00);

            // Call the base method to generate the markup.
            markup = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // Restore the properties to their original settings.
            myMenuCtl.BorderStyle = oldBorderStyle;
            myMenuCtl.BorderColor = oldBorderColor;
        }
    }
    else
    {
        // Call the base method to generate the markup.
        markup = base.GetDesignTimeHtml();
    }

    return markup;
} // GetDesignTimeHtml
' Generate the design-time markup.
Public Overrides Function GetDesignTimeHtml() As String

    ' Make the control more visible in the designer.  If the border 
    ' style is None or NotSet, change the border to an orange dotted line. 
    Dim myMenuCtl As MyMenu = CType(ViewControl, MyMenu)
    Dim markup As String = Nothing

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

        Dim oldBorderStyle As BorderStyle = myMenuCtl.BorderStyle
        Dim oldBorderColor As Color = myMenuCtl.BorderColor

        ' Set the design-time properties and catch any exceptions.
        Try
            myMenuCtl.BorderStyle = BorderStyle.Dotted
            myMenuCtl.BorderColor = Color.FromArgb(&HFF7F00)

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

        Catch ex As Exception
            markup = GetErrorDesignTimeHtml(ex)

        Finally
            ' Restore the properties to their original settings.
            myMenuCtl.BorderStyle = oldBorderStyle
            myMenuCtl.BorderColor = oldBorderColor
        End Try

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

    Return markup

End Function ' GetDesignTimeHtml

備註

方法 GetDesignTimeHtmlDataBind 呼叫 方法,將設計階段資料來源系結至相關聯的 Menu 控制項,然後 GetDesignTimeHtml 呼叫 GetDesignModeState 方法,讓 Menu 控制項產生其靜態檢視和動態檢視標記。 會 GetDesignTimeHtml 傳回目前檢視的標記。 如果未定義目前的檢視,則會 GetDesignTimeHtml 呼叫 GetDesignTimeHtml 基底方法。

適用於

另請參閱