.NET Framework Class Library MenuItemStyle Class Represents the style of a menu item in a Menu control. This class cannot be inherited.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public NotInheritable Class MenuItemStyle _
Inherits Style
public sealed class MenuItemStyle : Style
public ref class MenuItemStyle sealed : public Style
[<Sealed>]
type MenuItemStyle =
class
inherit Style
end
The MenuItemStyle type exposes the following members.

Constructors

Methods

Events

Explicit Interface Implementations

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. When multiple style properties are set for a static menu item, the style properties are applied in the following order: StaticMenuStyle. StaticMenuItemStyle. If the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties. StaticSelectedStyle. If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties. StaticHoverStyle.
Likewise, the style properties for a dynamic menu item are applied in the following order: DynamicMenuStyle. DynamicMenuItemStyle. If the LevelMenuItemStyles collection or LevelSubMenuStyles collection is defined, it is applied at this time, overriding the other menu item style properties. DynamicSelectedStyle. If the LevelSelectedStyles collection is defined, it is applied at this time, overriding the other menu item style properties. 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.

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="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- 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="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- 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>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also
|
Bibliothèque de classes .NET Framework MenuItemStyle, classe Représente le style d'un élément de menu d'un contrôle Menu. Cette classe ne peut pas être héritée.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public NotInheritable Class MenuItemStyle _
Inherits Style
public sealed class MenuItemStyle : Style
public ref class MenuItemStyle sealed : public Style
[<Sealed>]
type MenuItemStyle =
class
inherit Style
end
Le type MenuItemStyle expose les membres suivants.

Constructeurs

Méthodes

Événements

Implémentations d'interface explicite

Notes
Utilisez la classe MenuItemStyle pour représenter le style d'un élément de menu dans le contrôle Menu. Un élément de menu s'affiche dans un menu statique ou un dans un menu dynamique. Un menu statique s'affiche toujours dans un contrôle Menu, tandis qu'un menu dynamique ne s'affiche que lorsque l'utilisateur positionne le pointeur de la souris sur un élément de menu parent qui contient un sous-menu dynamique. Vous pouvez spécifier différentes caractéristiques de style (par exemple la taille et la couleur de la police) pour chacun des différents types d'éléments de menu. Le tableau suivant répertorie les styles d'élément de menu disponibles. Propriété de style d'élément de menu | Description |
|---|
DynamicHoverStyle | Paramètres de style d'un élément de menu dynamique lorsque le pointeur de la souris est positionné sur lui. | DynamicMenuItemStyle | Paramètres de style d'un élément de menu dynamique. | DynamicMenuStyle | Paramètres de style d'un menu dynamique. | DynamicSelectedStyle | Paramètres de style de l'élément de menu dynamique actuellement sélectionné. | StaticHoverStyle | Paramètres de style d'un élément de menu statique lorsque le pointeur de la souris est positionné sur lui. | StaticMenuItemStyle | Paramètres de style d'un élément de menu statique. | StaticMenuStyle | Paramètres de style d'un menu statique. | StaticSelectedStyle | Paramètres de style de l'élément de menu statique actuellement sélectionné. |
Lorsque plusieurs propriétés de style d'un élément de menu statique sont définies, les propriétés de style sont appliquées dans l'ordre suivant : StaticMenuStyle. StaticMenuItemStyle. Si la collection LevelMenuItemStyles ou LevelSubMenuStyles est définie, elle est alors appliquée et les autres propriétés de style des éléments de menu sont substituées. StaticSelectedStyle. Si la collection LevelSelectedStyles est définie, elle est alors appliquée et les autres propriétés de style des éléments de menu sont substituées. StaticHoverStyle.
De même, les propriétés de style d'un élément de menu dynamique sont appliquées dans l'ordre suivant : DynamicMenuStyle. DynamicMenuItemStyle. Si la collection LevelMenuItemStyles ou LevelSubMenuStyles est définie, elle est alors appliquée et les autres propriétés de style des éléments de menu sont substituées. DynamicSelectedStyle. Si la collection LevelSelectedStyles est définie, elle est alors appliquée et les autres propriétés de style des éléments de menu sont substituées. DynamicHoverStyle.
La classe MenuItemStyle hérite la plupart de ses membres de la classe Style. Elle étend la classe Style en fournissant des propriétés qui contrôlent l'espace qui entoure le texte d'un élément de menu, ainsi que l'espace entre les éléments de menu adjacents. Utilisez la propriété HorizontalPadding pour contrôler l'espace à gauche et à droit du texte de l'élément de menu. De même, la propriété VerticalPadding contrôle l'espace au-dessus et en dessous du texte de l'élément de menu. Vous pouvez contrôler l'espacement entre l'élément de menu auquel l'objet MenuItemStyle est appliqué et ses éléments de menu adjacents en définissant la propriété ItemSpacing. Pour plus d'informations sur les paramètres de style hérités, consultez Style.

Exemples
L'exemple de code suivant montre comment contrôler l'apparence des éléments de menu d'un contrôle Menu en définissant les propriétés de style de l'objet MenuItemStyle retourné des propriétés DynamicMenuItemStyle, DynamicHoverStyle, StaticMenuItemStyleet StaticHoverStyle.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- 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="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<!-- 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>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
|