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

屬性

範例

下列範例示範如何將屬性設定為 false 的功能表項目 Enabled 出現在功能表中,以及函式。


<%@ 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

適用於

另請參閱