MenuItem.Enabled 属性

定义

获取或设置一个值,该值指示 MenuItem 对象是否已启用,如果启用,则该项可以显示弹出图像和所有子菜单项。

public:
 property bool Enabled { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(true)]
public bool Enabled { get; set; }
[<System.ComponentModel.Browsable(true)>]
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

属性值

Boolean

如果启用菜单项,则为 true;否则为 false

属性

示例

以下示例演示如何在菜单中显示属性集falseEnabled菜单项和函数。


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Selectable and Enabled properties Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Selectable and Enabled properties Example</h3>
    Note that Home, set to Selectable=false, is unselectable, but still shows all child items.<br />
    Movies, set to Enabled=false, is unselectable, is greyed out, and does not show child items. <br />
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="1"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">
        
        <dynamicmenustyle backcolor="LightSkyBlue"
          forecolor="Black"
          borderstyle="Solid"
          borderwidth="1"
          bordercolor="Black" />
      
        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Non-Selectable"
            tooltip="Non-Selectable"
              Selectable="false">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Disabled"
              tooltip="Disabled"
              Enabled="false">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
                 
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Selectable and Enabled properties Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Selectable and Enabled properties Example</h3>
    Note that Home, set to Selectable=false, is unselectable, but still shows all child items.<br />
    Movies, set to Enabled=false, is unselectable, is greyed out, and does not show child items. <br />
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="1"
        staticsubmenuindent="10" 
        orientation="Vertical"
        target="_blank"  
        runat="server">
        
        <dynamicmenustyle backcolor="LightSkyBlue"
          forecolor="Black"
          borderstyle="Solid"
          borderwidth="1"
          bordercolor="Black" />
      
        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Non-Selectable"
            tooltip="Non-Selectable"
              Selectable="false">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Disabled"
              tooltip="Disabled"
              Enabled="false">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
                 
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

注解

当此属性设置为 false时,菜单项处于禁用状态,并且没有显示指示子项的弹出图像。 将此属性设置为 false 菜单项实质上使菜单项成为该节点的末尾,其中没有显示该节点的进一步级别。 默认值是 true

如果希望菜单项显示任何子项,但不能“可单击”本身,请使用 Selectable 该属性并将其设置为 false

适用于

另请参阅