แก้ไข

แชร์ผ่าน


MenuItemStyle Class

Definition

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
Inheritance

Examples

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>

Remarks

Use 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. 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.

  2. StaticMenuItemStyle. If the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  3. StaticSelectedStyle. If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  4. StaticHoverStyle.

Likewise, the style properties for a dynamic menu item are applied in the following order:

  1. DynamicMenuStyle.

  2. DynamicMenuItemStyle. If the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  3. DynamicSelectedStyle. If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties.

  4. DynamicHoverStyle.

The MenuItemStyle class inherits most of its members from the Style class. 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. Use the HorizontalPadding property to control the amount of space to the left and right of the menu item's text. Similarly, the VerticalPadding property controls the amount of space above and below the menu item's text. 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.

For more information on the inherited style settings, see Style.

Constructors

MenuItemStyle()

Initializes a new instance of the MenuItemStyle class.

MenuItemStyle(StateBag)

Initializes a new instance of the MenuItemStyle class using the specified state information.

Properties

BackColor

Gets or sets the background color of the Web server control.

(Inherited from Style)
BorderColor

Gets or sets the border color of the Web server control.

(Inherited from Style)
BorderStyle

Gets or sets the border style of the Web server control.

(Inherited from Style)
BorderWidth

Gets or sets the border width of the Web server control.

(Inherited from Style)
CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container

Gets the IContainer that contains the Component.

(Inherited from Component)
CssClass

Gets or sets the cascading style sheet (CSS) class rendered by the Web server control on the client.

(Inherited from Style)
DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Font

Gets the font properties associated with the Web server control.

(Inherited from Style)
ForeColor

Gets or sets the foreground color (typically the color of the text) of the Web server control.

(Inherited from Style)
Height

Gets or sets the height of the Web server control.

(Inherited from Style)
HorizontalPadding

Gets or sets the amount of space to the left and right of the menu item's text.

IsEmpty

A protected property. Gets a value indicating whether any style elements have been defined in the state bag.

(Inherited from Style)
IsTrackingViewState

Returns a value indicating whether any style elements have been defined in the state bag.

(Inherited from Style)
ItemSpacing

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

Gets the cascading style sheet (CSS) class that is registered with the control.

(Inherited from Style)
Site

Gets or sets the ISite of the Component.

(Inherited from 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.

(Inherited from Style)
Width

Gets or sets the width of the Web server control.

(Inherited from Style)

Methods

AddAttributesToRender(HtmlTextWriter, WebControl)

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.

(Inherited from Style)
AddAttributesToRender(HtmlTextWriter)

Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter. This method is primarily used by control developers.

(Inherited from Style)
CopyFrom(Style)

Copies the style properties of the specified Style object into the current instance of the MenuItemStyle class.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
FillStyleAttributes(CssStyleCollection, IUrlResolutionService)

Adds the specified object's style properties to a CssStyleCollection object.

(Inherited from Style)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetStyleAttributes(IUrlResolutionService)

Retrieves the CssStyleCollection object for the specified IUrlResolutionService-implemented object.

(Inherited from Style)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
LoadViewState(Object)

Loads the previously saved state.

(Inherited from Style)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
MergeWith(Style)

Combines the style properties of the specified Style object with those of the current instance of the MenuItemStyle class.

Reset()

Returns the current instance of the MenuItemStyle class to its original state.

SaveViewState()

A protected method. Saves any state that has been modified after the TrackViewState() method was invoked.

(Inherited from Style)
SetBit(Int32)

A protected internal method. Sets an internal bitmask field that indicates the style properties that are stored in the state bag.

(Inherited from Style)
SetDirty()

Marks the Style so that its state will be recorded in view state.

(Inherited from Style)
ToString()

Returns a string that represents the current object.

(Inherited from Style)
TrackViewState()

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.

(Inherited from Style)

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Explicit Interface Implementations

IStateManager.IsTrackingViewState

Gets a value that indicates whether a server control is tracking its view state changes.

(Inherited from Style)
IStateManager.LoadViewState(Object)

Loads the previously saved state.

(Inherited from Style)
IStateManager.SaveViewState()

Returns the object containing state changes.

(Inherited from Style)
IStateManager.TrackViewState()

Starts tracking state changes.

(Inherited from Style)

Applies to

See also