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 的标记。

示例

下面的代码示例演示如何重写 GetDesignTimeHtmlMenuDesigner 类继承的类中的 方法。 重写的方法更改在设计时派生自控件的 Menu 控件的外观。 如果 BorderStyle 控件的 属性为 NotSetNone 值,则本示例在控件周围绘制一个橙色虚线边框,使其范围更加可见。

// 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

注解

方法 GetDesignTimeHtml 调用 DataBind 方法以将设计时数据源绑定到关联的 Menu 控件,然后 GetDesignTimeHtml 调用 GetDesignModeState 方法,使 Menu 控件生成其静态视图和动态视图标记。 返回 GetDesignTimeHtml 当前视图的标记。 如果未定义当前视图,则 GetDesignTimeHtml 调用 GetDesignTimeHtml 基方法。

适用于

另请参阅