MenuItemStyle 類別

定義

表示 Menu 控制項中的功能表項目樣式。Represents the style of a menu item in a Menu control. 這個類別無法被繼承。This class cannot be inherited.

public ref class MenuItemStyle sealed : System::Web::UI::WebControls::Style
public sealed class MenuItemStyle : System.Web.UI.WebControls.Style
type MenuItemStyle = class
    inherit Style
Public NotInheritable Class MenuItemStyle
Inherits Style
繼承

範例

下列程式碼範例示範如何藉由設定從Menu DynamicMenuItemStyle、、 StaticMenuItemStyleMenuItemStyle DynamicHoverStyle StaticHoverStyle傳回之物件的樣式屬性,控制控制項中功能表項目的外觀。屬性。The following code example demonstrates how to control the appearance of the menu items in a Menu control by setting the style properties of the MenuItemStyle object returned from the DynamicMenuItemStyle, DynamicHoverStyle, StaticMenuItemStyle, and StaticHoverStyle properties.


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

  <!-- For the hover styles of the Menu control to  -->
  <!-- work correctly, you must include this head   -->
  <!-- element.                                     -->
  <head runat="server">
    <title>MenuItemStyle Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>MenuItemStyle Example</h3>
    
      <!-- Set the style properties of the        -->
      <!-- MenuItemStyle objects contained in the -->
      <!-- StaticMenuItemStyle, StaticHoverStyle, -->
      <!-- DynamicMenuItemStyle, and              -->
      <!-- DynamicHoverStyle properties.          -->
      
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticmenuitemstyle backcolor="LightSteelBlue"
          horizontalpadding="5"
          verticalpadding="2"
          font-names="Arial"   
          forecolor="Black"/>
        <statichoverstyle backcolor="LightSkyBlue"
          font-names="Arial"
          forecolor="Red"/>
        <dynamicmenuitemstyle backcolor="Black"
          horizontalpadding="10"
          verticalpadding="4"
          itemspacing="2"
          font-names="Arial"
          forecolor="Silver"/>
        <dynamichoverstyle backcolor="LightSkyBlue"
          font-names="Arial"
          forecolor="Red"/>
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

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


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

  <!-- For the hover styles of the Menu control to  -->
  <!-- work correctly, you must include this head   -->
  <!-- element.                                     -->
  <head runat="server">
    <title>MenuItemStyle Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>MenuItemStyle Example</h3>
    
      <!-- Set the style properties of the        -->
      <!-- MenuItemStyle objects contained in the -->
      <!-- StaticMenuItemStyle, StaticHoverStyle, -->
      <!-- DynamicMenuItemStyle, and              -->
      <!-- DynamicHoverStyle properties.          -->
      
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        runat="server">
        
        <staticmenuitemstyle backcolor="LightSteelBlue"
          horizontalpadding="5"
          verticalpadding="2"
          font-names="Arial"   
          forecolor="Black"/>
        <statichoverstyle backcolor="LightSkyBlue"
          font-names="Arial"
          forecolor="Red"/>
        <dynamicmenuitemstyle backcolor="Black"
          horizontalpadding="10"
          verticalpadding="4"
          itemspacing="2"
          font-names="Arial"
          forecolor="Silver"/>
        <dynamichoverstyle backcolor="LightSkyBlue"
          font-names="Arial"
          forecolor="Red"/>
      
        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Music"
              tooltip="Music">
              <asp:menuitem text="Classical"
                tooltip="Classical"/>
              <asp:menuitem text="Rock"
                tooltip="Rock"/>
              <asp:menuitem text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem text="Movies"
              tooltip="Movies">
              <asp:menuitem text="Action"
                tooltip="Action"/>
              <asp:menuitem text="Drama"
                tooltip="Drama"/>
              <asp:menuitem text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

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

備註

使用類別來表示Menu控制項中功能表項目的樣式。 MenuItemStyleUse the MenuItemStyle class to represent the style of a menu item in the Menu control. 功能表項目會顯示在 [靜態] 功能表或動態功能表中。A menu item is displayed in either a static menu or a dynamic menu. 靜態功能表一律會顯示在Menu控制項中, 而只有在使用者將滑鼠指標放在包含動態子功能表的父功能表項目目上方時, 才會顯示動態功能表。A static menu is always displayed in a Menu control, whereas a dynamic menu is displayed only when the user positions the mouse pointer over a parent menu item that contains a dynamic submenu. 您可以為每個不同的功能表項目類型指定不同的樣式特性 (例如字型大小和色彩)。You can specify different style characteristics (such as font size and color) for each of the different menu item types. 下表列出可用的功能表項目樣式。The following table lists the available menu item styles.

功能表項目樣式屬性Menu item style property 說明Description
DynamicHoverStyle 當滑鼠指標位於動態功能表項目上方時的樣式設定。The style settings for a dynamic menu item when the mouse pointer is positioned over it.
DynamicMenuItemStyle 個別動態功能表項目的樣式設定。The style settings for an individual dynamic menu item.
DynamicMenuStyle 動態功能表的樣式設定。The style settings for a dynamic menu.
DynamicSelectedStyle 目前選取之動態功能表項目的樣式設定。The style settings for the currently selected dynamic menu item.
StaticHoverStyle 當滑鼠指標位於靜態功能表項目上時, 該專案的樣式設定。The style settings for a static menu item when the mouse pointer is positioned over it.
StaticMenuItemStyle 個別靜態功能表項目的樣式設定。The style settings for an individual static menu item.
StaticMenuStyle 靜態功能表的樣式設定。The style settings for a static menu.
StaticSelectedStyle 目前所選取之靜態功能表項目的樣式設定。The style settings for the currently selected static menu item.

設定靜態功能表項目的多個樣式屬性時, 會依下列順序套用樣式屬性:When multiple style properties are set for a static menu item, the style properties are applied in the following order:

  1. StaticMenuStyle.StaticMenuStyle.

  2. StaticMenuItemStyle.StaticMenuItemStyle. 如果已定義LevelSubMenuStyles集合或集合, 則會在此時套用, 並覆寫其他功能表項目樣式屬性。 LevelMenuItemStylesIf the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  3. StaticSelectedStyle.StaticSelectedStyle. LevelSelectedStyles如果集合已定義, 則會在此時套用, 並覆寫其他功能表項目樣式屬性。If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  4. StaticHoverStyle.StaticHoverStyle.

同樣地, 動態功能表項目的樣式屬性會依照下列順序套用:Likewise, the style properties for a dynamic menu item are applied in the following order:

  1. DynamicMenuStyle.DynamicMenuStyle.

  2. DynamicMenuItemStyle.DynamicMenuItemStyle. 如果已定義LevelSubMenuStyles集合或集合, 則會在此時套用, 並覆寫其他功能表項目樣式屬性。 LevelMenuItemStylesIf the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  3. DynamicSelectedStyle.DynamicSelectedStyle. LevelSelectedStyles如果集合已定義, 則會在此時套用, 並覆寫其他功能表項目樣式屬性。If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  4. DynamicHoverStyle.DynamicHoverStyle.

MenuItemStyle類別會Style從類別繼承其大部分的成員。The MenuItemStyle class inherits most of its members from the Style class. 它會藉Style由提供屬性來控制功能表項目文字周圍的空間量, 以及相鄰功能表項目之間的空間, 藉以擴充類別。It extends the Style class by providing properties that control the amount of space around a menu item's text, as well as the space between adjacent menu items. HorizontalPadding使用屬性, 即可控制功能表項目文字左邊和右邊的空間量。Use the HorizontalPadding property to control the amount of space to the left and right of the menu item's text. 同樣地, VerticalPadding屬性會控制功能表項目文字上方和下方的空間量。Similarly, the VerticalPadding property controls the amount of space above and below the menu item's text. 您可以藉由MenuItemStyle ItemSpacing設定屬性, 來控制套用物件的功能表項目和其相鄰功能表項目之間的間距大小。You can control the amount of spacing between the menu item that the MenuItemStyle object is applied to and its adjacent menu items by setting the ItemSpacing property.

如需繼承樣式設定的詳細資訊, 請Style參閱。For more information on the inherited style settings, see Style.

建構函式

MenuItemStyle()

初始化 MenuItemStyle 類別的新執行個體。Initializes a new instance of the MenuItemStyle class.

MenuItemStyle(StateBag)

使用指定的狀態資訊,初始化 MenuItemStyle 類別的新執行個體。Initializes a new instance of the MenuItemStyle class using the specified state information.

屬性

BackColor

取得或設定 Web 伺服器控制項的背景色彩。Gets or sets the background color of the Web server control.

(繼承來源 Style)
BorderColor

取得或設定 Web 伺服器控制項的框線色彩。Gets or sets the border color of the Web server control.

(繼承來源 Style)
BorderStyle

取得或設定 Web 伺服器控制項的框線樣式。Gets or sets the border style of the Web server control.

(繼承來源 Style)
BorderWidth

取得或設定 Web 伺服器控制項的框線寬度。Gets or sets the border width of the Web server control.

(繼承來源 Style)
CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
CssClass

取得或設定用戶端上 Web 伺服器控制項所呈現的階層式樣式表 (CSS)。Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(繼承來源 Style)
DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
Font

取得與 Web 伺服器控制項關聯的字型屬性。Gets the font properties associated with the Web server control.

(繼承來源 Style)
ForeColor

取得或設定 Web 伺服器控制項的前景色彩 (通常是文字的色彩)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(繼承來源 Style)
Height

取得或設定 Web 伺服器控制項的高度。Gets or sets the height of the Web server control.

(繼承來源 Style)
HorizontalPadding

取得或設定功能表項目文字左側和右側的間距。Gets or sets the amount of space to the left and right of the menu item's text.

IsEmpty

保護的 (Protected) 屬性。A protected property. 取得值,指出狀態包中是否已定義任何樣式項目。Gets a value indicating whether any style elements have been defined in the state bag.

(繼承來源 Style)
IsTrackingViewState

傳回值,指出是否任何的樣式項目都已經在狀態包中定義。Returns a value indicating whether any style elements have been defined in the state bag.

(繼承來源 Style)
ItemSpacing

取得或設定套用 MenuItemStyle 物件之功能表項目與其相鄰功能表項目的垂直間距。Gets or sets the amount of vertical spacing between the menu item to which the MenuItemStyle object is applied and its adjacent menu items.

RegisteredCssClass

取得使用控制項註冊的階層式樣式表 (CSS) 類別。Gets the cascading style sheet (CSS) class that is registered with the control.

(繼承來源 Style)
Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
VerticalPadding

取得或設定功能表項目文字上方和下方的間距。Gets or sets the amount of space above and below a menu item's text.

ViewState

取得保存樣式項目的狀態包。Gets the state bag that holds the style elements.

(繼承來源 Style)
Width

取得或設定 Web 伺服器控制項的寬度。Gets or sets the width of the Web server control.

(繼承來源 Style)

方法

AddAttributesToRender(HtmlTextWriter)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. 這個方法主要由控制項開發人員使用。This method is primarily used by control developers.

(繼承來源 Style)
AddAttributesToRender(HtmlTextWriter, WebControl)

將需要呈現的 HTML 屬性和樣式加入至指定的 HtmlTextWriter 和 Web 伺服器控制項中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter and Web server control. 這個方法主要由控制項開發人員使用。This method is primarily used by control developers.

(繼承來源 Style)
CopyFrom(Style)

將指定 Style 物件的樣式屬性複製到 MenuItemStyle 類別的目前執行個體中。Copies the style properties of the specified Style object into the current instance of the MenuItemStyle class.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

將指定物件的樣式屬性加入 CssStyleCollection 物件中。Adds the specified object's style properties to a CssStyleCollection object.

(繼承來源 Style)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetStyleAttributes(IUrlResolutionService)

擷取指定 CssStyleCollection 實作物件的 IUrlResolutionService 物件。Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(繼承來源 Style)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
LoadViewState(Object)

載入先前儲存的狀態。Loads the previously saved state.

(繼承來源 Style)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
MergeWith(Style)

將指定 Style 物件的樣式屬性與 MenuItemStyle 類別目前執行個體的樣式屬性結合。Combines the style properties of the specified Style object with those of the current instance of the MenuItemStyle class.

Reset()

MenuItemStyle 類別的目前執行個體返回其原始狀態。Returns the current instance of the MenuItemStyle class to its original state.

SaveViewState()

保護的 (Protected) 方法。A protected method. 儲存叫用 TrackViewState() 方法之後,任何已變更的狀態。Saves any state that has been modified after the TrackViewState() method was invoked.

(繼承來源 Style)
SetBit(Int32)

保護的內部方法。A protected internal method. 設定內部位元遮罩欄位,表示儲存在狀態包中的樣式屬性。Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(繼承來源 Style)
SetDirty()

標記 Style,以便將其狀態記錄在檢視狀態中。Marks the Style so that its state will be recorded in view state.

(繼承來源 Style)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Style)
TrackViewState()

保護的 (Protected) 方法。A protected method. 在控制項上標記追蹤狀態變更的開頭。Marks the beginning for tracking state changes on the control. 任何在追蹤開始後的變更都會被追蹤,並儲存成控制項檢視狀態的一部分。Any changes made after tracking has begun will be tracked and saved as part of the control view state.

(繼承來源 Style)

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)

明確介面實作

IStateManager.IsTrackingViewState

取得值,指出伺服器控制項是否正在追蹤其檢視狀態變更。Gets a value that indicates whether a server control is tracking its view state changes.

(繼承來源 Style)
IStateManager.LoadViewState(Object)

載入先前儲存的狀態。Loads the previously saved state.

(繼承來源 Style)
IStateManager.SaveViewState()

傳回包含狀態變更的物件。Returns the object containing state changes.

(繼承來源 Style)
IStateManager.TrackViewState()

啟動追蹤狀態的變更。Starts tracking state changes.

(繼承來源 Style)

適用於

另請參閱