MenuDesigner 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在可视化设计器中为 Menu 控件提供设计时支持。
public ref class MenuDesigner : System::Web::UI::Design::WebControls::HierarchicalDataBoundControlDesigner, System::Web::UI::Design::IDataBindingSchemaProviderpublic class MenuDesigner : System.Web.UI.Design.WebControls.HierarchicalDataBoundControlDesigner, System.Web.UI.Design.IDataBindingSchemaProvidertype MenuDesigner = class
    inherit HierarchicalDataBoundControlDesigner
    interface IDataBindingSchemaProviderPublic Class MenuDesigner
Inherits HierarchicalDataBoundControlDesigner
Implements IDataBindingSchemaProvider- 继承
- 实现
示例
下面的代码示例演示如何扩展 MenuDesigner 类,以在设计时更改派生自 控件的 Menu 控件的外观。
该示例从 Menu派生MyMenu类。 类 MyMenu 是 的副本 Menu。 该示例还从 类派生MyMenuDesigner类,然后对 类应用 DesignerAttribute 特性MyMenuDesignerMyMenu。MenuDesigner
              The MyMenuDesigner 重写以下 MenuDesigner 成员:
- 在 GetDesignTimeHtml 控件周围绘制橙色虚线边框以使其范围更可见的方法。 
- 为 GetErrorDesignTimeHtml 包含错误消息的占位符生成标记的方法,该占位符以红色粗体文本呈现。 
- 为 GetEmptyDesignTimeHtml 包含指示未定义菜单项的消息的占位符生成标记的 。 
- Initialize如果关联的控件不是 - MyMenu对象,则引发ArgumentException异常的方法。
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.Security.Permissions;
using System.Drawing;
namespace Examples.CS.WebControls.Design
{
    // The MyMenu is a copy of the Menu.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.MyMenuDesigner))]
    public class MyMenu : Menu
    {
    } // MyMenu
    // Override members of the MenuDesigner.
    public class MyMenuDesigner : MenuDesigner
    {
        // Generate the design-time markup for the control when an error occurs.
        protected override string GetErrorDesignTimeHtml(Exception ex) 
        {
            // Write the error message text in red, bold.
            string errorRendering =
                "<span style=\"font-weight:bold; color:Red; \">" +
                ex.Message + "</span>";
            return CreatePlaceHolderDesignTimeHtml(errorRendering);
        } // GetErrorDesignTimeHtml
        // Generate the design-time markup for the control 
        // when the template is empty.
        protected override string GetEmptyDesignTimeHtml()
        {
            string noElements = "Contains no menu items.";
            return CreatePlaceHolderDesignTimeHtml(noElements);
        } // GetEmptyDesignTimeHtml
        // 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
        public override void Initialize(IComponent component)
        {
            // Ensure that only a MyMenu can be created in this designer.
            if (!(component is MyMenu))
                throw new ArgumentException(
                    "The component is not a MyMenu control.");
            
            base.Initialize(component);
        } // Initialize
    } // MyMenuDesigner
} // Examples.CS.WebControls.Design
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Drawing
Namespace Examples.VB.WebControls.Design
    ' The MyMenu is a copy of the Menu.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.MyMenuDesigner))> _
    Public Class MyMenu
        Inherits Menu
    End Class
    ' Override members of the MenuDesigner.
    Public Class MyMenuDesigner
        Inherits MenuDesigner
        ' Generate the design-time markup for the control when an error occurs.
        Protected Overrides Function GetErrorDesignTimeHtml( _
            ByVal ex As Exception) As String
            ' Write the error message text in red, bold.
            Dim errorRendering As String = _
                "<span style=""font-weight:bold; color:Red; "">" & _
                ex.Message & "</span>"
            Return CreatePlaceHolderDesignTimeHtml(errorRendering)
        End Function ' GetErrorDesignTimeHtml
        ' Generate the design-time markup for the control 
        ' when the template is empty.
        Protected Overrides Function GetEmptyDesignTimeHtml() As String
            Dim noElements As String = "Contains no menu items."
            Return CreatePlaceHolderDesignTimeHtml(noElements)
        End Function ' GetEmptyDesignTimeHtml
        ' 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
        Public Overrides Sub Initialize(ByVal component As IComponent)
            ' Ensure that only a MyMenu can be created in this designer. 
            If Not TypeOf component Is MyMenu Then
                Throw New ArgumentException( _
                    "The component is not a MyMenu control.")
            End If
            MyBase.Initialize(component)
        End Sub
    End Class
End Namespace ' Examples.VB.WebControls.Design
注解
类 Menu 提供分层菜单 Web 服务器控件。
在可视化设计器中,从“源”视图切换到“设计”视图时,将分析描述关联 Menu 控件的标记源代码,并在设计图面上创建控件的设计时版本。 切换回“源”视图时,设计时控件将保留到标记中,并添加到网页的现有标记中。 类 MenuDesigner 为 Menu 可视化设计器中的控件提供设计时支持。
属性 ActionLists 返回 一个 DesignerActionListCollection 对象,该对象通常包含从 DesignerActionList 设计器继承树中每个级别的 类派生的对象。 属性 AutoFormats 返回用于在“ 自动格式 ”对话框中显示的格式设置方案的集合。
属性 TemplateGroups 返回关联 Menu 控件的模板的模板组的集合。 属性 UsePreviewControl 始终返回 true,指示设计器创建关联的 Menu 的临时副本以生成设计时标记。
类 MenuDesigner 方法提供以下功能:
- 方法 Initialize 使设计器准备好查看、编辑和设计关联的 Menu 控件。 方法 GetDesignTimeHtml 返回用于在设计时呈现关联的 Menu 的标记。 
- 方法 GetEmptyDesignTimeHtml 获取标记,该标记在设计时呈现关联控件的占位符时,如果没有其他可用标记。 方法 GetErrorDesignTimeHtml 提供标记,该标记在发生错误时在设计时呈现关联的控件。 
- 方法 DataBind 将关联的 Menu 控件绑定到设计时数据源。 方法 GetSampleDataSource 构造可在设计时用于关联控件的示例数据源。 
构造函数
| MenuDesigner() | 初始化 MenuDesigner 类的新实例。 | 
属性
| ActionLists | 获取此设计器的设计器操作列表集合。 | 
| AllowResize | 获取一个值,该值指示是否可以在设计时环境中调整控件的大小。(继承自 ControlDesigner) | 
| AssociatedComponents | 获取与设计器所管理的组件关联的组件集合。(继承自 ComponentDesigner) | 
| AutoFormats | 获取预定义的格式设置方案的集合,以便在“自动套用格式”对话框中显示。 | 
| Behavior | 
		已过时.
	 获取或设置与设计器关联的 DHTML 行为。(继承自 HtmlControlDesigner) | 
| CanRefreshSchema | 获取一个值,该值指示提供程序是否可以刷新架构。 | 
| Component | 获取此设计器正在设计的组件。(继承自 ComponentDesigner) | 
| DataBindings | 获取当前控件的数据绑定集合。(继承自 HtmlControlDesigner) | 
| DataBindingsEnabled | 获取一个值,该值指示包含关联控件的区域是否支持数据绑定。(继承自 ControlDesigner) | 
| DataSource | 获取或设置关联控件的 DataSource 属性值。(继承自 BaseDataBoundControlDesigner) | 
| DataSourceDesigner | 用于访问数据源的设计器(如果已为数据绑定选择了设计器)。(继承自 HierarchicalDataBoundControlDesigner) | 
| DataSourceID | 获取或设置基础 DataSourceID 对象的 BaseDataBoundControl 属性值。(继承自 BaseDataBoundControlDesigner) | 
| DesignerState | 获取用于在设计时保持关联控件数据的对象。(继承自 ControlDesigner) | 
| DesignerView | 获取与关联控件绑定的数据源的默认视图。(继承自 HierarchicalDataBoundControlDesigner) | 
| DesignTimeElement | 
		已过时.
	 获取一个设计时对象,该对象表示与设计图面上的 HtmlControlDesigner 对象关联的控件。(继承自 HtmlControlDesigner) | 
| DesignTimeElementView | 
		已过时.
	 获取控件设计器的视图控件对象。(继承自 ControlDesigner) | 
| DesignTimeHtmlRequiresLoadComplete | 
		已过时.
	 获取一个值,该值指示是否必须在设计宿主完成加载之后才能调用 GetDesignTimeHtml 方法。(继承自 ControlDesigner) | 
| Expressions | 获取当前控件在设计时的表达式绑定。(继承自 HtmlControlDesigner) | 
| HidePropertiesInTemplateMode | 获取一个值,该值指示当控件处于模板模式时,关联控件的属性是否被隐藏。(继承自 ControlDesigner) | 
| ID | 获取或设置控件的 ID 字符串。(继承自 ControlDesigner) | 
| InheritanceAttribute | 获取一个特性,该特性指示关联组件的继承类型。(继承自 ComponentDesigner) | 
| Inherited | 获取一个值,该值指示是否继承此组件。(继承自 ComponentDesigner) | 
| InTemplateMode | 获取一个值,该值指示控件在设计宿主中是否处于模板查看模式或模板编辑模式之一。 InTemplateMode 属性为只读。(继承自 ControlDesigner) | 
| IsDirty | 
		已过时.
	 获取或设置一个值,该值指示 Web 服务器控件是否已被标记为已更改。(继承自 ControlDesigner) | 
| ParentComponent | 获取此设计器的父组件。(继承自 ComponentDesigner) | 
| ReadOnly | 
		已过时.
	 获取或设置一个值,该值指示控件的属性在设计时是否为只读。(继承自 ControlDesigner) | 
| RootDesigner | 获取包含关联控件的 Web 窗体页的控件设计器。(继承自 ControlDesigner) | 
| Schema | 获取描述关联的 Menu 控件的数据源视图的架构。 | 
| SetTextualDefaultProperty | 在可视化设计器中为 Menu 控件提供设计时支持。(继承自 ComponentDesigner) | 
| ShadowProperties | 获取重写用户设置的属性值的集合。(继承自 ComponentDesigner) | 
| ShouldCodeSerialize | 
		已过时.
	 获取或设置一个值,该值指示在序列化期间是否应为当前设计文档在代码隐藏文件中创建控件的字段声明。(继承自 HtmlControlDesigner) | 
| Tag | 获取表示关联控件的 HTML 标记元素的对象。(继承自 ControlDesigner) | 
| TemplateGroups | 获取用于关联控件的模板组集合。 | 
| UseDataSourcePickerActionList | 获取一个值,该值指示控件是否应呈现其默认操作列表,该操作列表包含一个数据源 ID 下拉列表和相关任务。(继承自 HierarchicalDataBoundControlDesigner) | 
| UsePreviewControl | 获取一个值,该值指示设计器应使用关联控件的副本还是应使用控件本身来生成设计时标记。 | 
| Verbs | 获取与设计器相关联的组件所支持的设计时谓词。(继承自 ComponentDesigner) | 
| ViewControl | 获取或设置可用于预览设计时 HTML 标记的 Web 服务器控件。(继承自 ControlDesigner) | 
| ViewControlCreated | 获取或设置一个值,该值指示是否已创建  | 
| Visible | 获取指示该控件在设计时是否可见的值。(继承自 ControlDesigner) |