Partager via


StyleSheet, classe

Organise des styles qui s'appliqueront à d'autres contrôles.

Espace de noms : System.Web.UI.MobileControls
Assembly : System.Web.Mobile (dans system.web.mobile.dll)

Syntaxe

'Déclaration
Public Class StyleSheet
    Inherits MobileControl
'Utilisation
Dim instance As StyleSheet
public class StyleSheet : MobileControl
public ref class StyleSheet : public MobileControl
public class StyleSheet extends MobileControl
public class StyleSheet extends MobileControl

Notes

Un contrôle StyleSheet peut contenir un nombre quelconque d'objets de style ou des objets de style plus spécialisés qui héritent de la classe Style. Ceux-ci doivent avoir des propriétés de noms uniques. Vous pouvez ensuite faire référence à d'autres contrôles sur la même page par leur propriété Name. Cette classe n'a aucune représentation visuelle.

Une page peut également utiliser une feuille de style externe et plusieurs pages peuvent partager la même feuille de style externe. Pour plus d'informations sur les styles, consultez l'élément <Style>, élément et la rubrique Styles.

Notes

Le contrôle StyleSheet ignore ses propres attributs de style ; la définition d'un attribut de style sur le StyleSheet lui-même n'a aucun effet sur les styles contenus comme enfants dans le contrôle StyleSheet.

Exemple

L'exemple suivant montre comment ajouter des propriétés Style à un contrôle StyleSheet pendant l'événement Page_Load.

<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            StyleSheet1("Style1").ForeColor = Color.Red
            StyleSheet1("Style1").Font.Size = _
                System.Web.UI.MobileControls.FontSize.Large
            StyleSheet1("Style1").Font.Bold = BooleanOption.True
            StyleSheet1("Style1").Font.Italic = BooleanOption.True
            StyleSheet1("Style2").ForeColor = Color.Blue
            StyleSheet1("Style2").Font.Size = _
                System.Web.UI.MobileControls.FontSize.Normal
            StyleSheet1("Style2").Font.Bold = BooleanOption.False
            StyleSheet1("Style2").Font.Italic = BooleanOption.True
            StyleSheet1("Style3").ForeColor = Color.Green
            StyleSheet1("Style3").Font.Size = _
                System.Web.UI.MobileControls.FontSize.Small
            StyleSheet1("Style3").Font.Bold = BooleanOption.False
            StyleSheet1("Style3").Font.Italic = BooleanOption.False
        End If
    End Sub

    Private Sub SelectStyle(ByVal sender As Object, _
        ByVal e As EventArgs)

        ' Retrieve the style name as a string.
        Dim myStyle As String = SelectionList1.Selection.ToString()

        ' Match the style name and apply the style to TextView1.
        Select Case myStyle
            Case "hot"
                TextView1.StyleReference = "Style1"
            Case "medium"
                TextView1.StyleReference = "Style2"
            Case "mild"
                TextView1.StyleReference = "Style3"
        End Select
    End Sub
</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:StyleSheet id="StyleSheet1" runat="server">
        <mobile:Style Name="Style1" Font-Name="Arial"
            BackColor="#E0E0E0" Wrapping="Wrap">
        </mobile:Style>
        <mobile:Style Name="Style2" Font-Name="Arial"
            BackColor="blue" Wrapping="NoWrap">
        </mobile:Style>
        <mobile:Style Name="Style3" Font-Name="Arial Narrow"
            BackColor="Green" Wrapping="NoWrap">
        </mobile:Style>
    </mobile:StyleSheet>

    <mobile:Form id="Form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Today's Special" StyleReference="title" />
        <mobile:TextView id="TextView1" runat="server" 
            StyleReference="Style1">Chili
        </mobile:TextView>
        <mobile:SelectionList runat="server" id="SelectionList1">
           <item Text="hot" Value="hot"/>
           <item Text="medium" Value="medium"/>
           <item Text="mild" Value="mild"/>
        </mobile:SelectionList>
        <mobile:Command ID="Command1" runat="server" 
           Text="Select Style" OnClick="SelectStyle" />
    </mobile:Form>
</body>
</html>
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">
    protected void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StyleSheet1["Style1"].ForeColor = Color.Red;
            StyleSheet1["Style1"].Font.Size = 
                System.Web.UI.MobileControls.FontSize.Large;
            StyleSheet1["Style1"].Font.Bold = BooleanOption.True;
            StyleSheet1["Style1"].Font.Italic = BooleanOption.True;
            StyleSheet1["Style2"].ForeColor = Color.Blue;
            StyleSheet1["Style2"].Font.Size = 
                System.Web.UI.MobileControls.FontSize.Normal;
            StyleSheet1["Style2"].Font.Bold = BooleanOption.False;
            StyleSheet1["Style2"].Font.Italic = BooleanOption.True;
            StyleSheet1["Style3"].ForeColor = Color.Green;
            StyleSheet1["Style3"].Font.Size = 
                System.Web.UI.MobileControls.FontSize.Small;
            StyleSheet1["Style3"].Font.Bold = BooleanOption.False;
            StyleSheet1["Style3"].Font.Italic = BooleanOption.False;
        }
    }

    void SelectStyle(object sender, EventArgs e)
    {
        // Retrieve the style name as a string.
        String myStyle = SelectionList1.Selection.ToString();

        // Match the style name and apply the style to TextView1.
        switch (myStyle)
        {
            case "hot":
                TextView1.StyleReference = "Style1";
                break;
            case "medium":
                TextView1.StyleReference = "Style2";
                break;
            case "mild":
                TextView1.StyleReference = "Style3";
                break;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:StyleSheet id="StyleSheet1" runat="server">
        <mobile:Style Name="Style1" Font-Name="Arial"
            BackColor="#E0E0E0" Wrapping="Wrap">
        </mobile:Style>
        <mobile:Style Name="Style2" Font-Name="Arial"
            BackColor="blue" Wrapping="NoWrap">
        </mobile:Style>
        <mobile:Style Name="Style3" Font-Name="Arial Narrow"
            BackColor="Green" Wrapping="NoWrap">
        </mobile:Style>
    </mobile:StyleSheet>

    <mobile:Form id="Form1" runat="server">
        <mobile:Label id="Label1" runat="server" 
            Text="Today's Special" StyleReference="title" />
        <mobile:TextView id="TextView1" runat="server" 
            StyleReference="Style1">Chili
        </mobile:TextView>
        <mobile:SelectionList runat="server" id="SelectionList1">
           <item Text="hot" Value="hot"/>
           <item Text="medium" Value="medium"/>
           <item Text="mild" Value="mild"/>
        </mobile:SelectionList>
        <mobile:Command ID="Command1" runat="server" 
           Text="Select Style" OnClick="SelectStyle" />
    </mobile:Form>
</body>
</html>

Sécurité .NET Framework

  • AspNetHostingPermission  pour opérer dans un environnement hébergé. Valeur de demande : LinkDemand ; valeur d'autorisation : Minimal
  • AspNetHostingPermission  pour opérer dans un environnement hébergé. Valeur de demande : InheritanceDemand ; valeur d'autorisation : Minimal

Hiérarchie d'héritage

System.Object
   System.Web.UI.Control
     System.Web.UI.MobileControls.MobileControl
      System.Web.UI.MobileControls.StyleSheet

Sécurité des threads

Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Plates-formes

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de version

.NET Framework

Prise en charge dans : 2.0, 1.1

Voir aussi

Référence

Membres StyleSheet
System.Web.UI.MobileControls, espace de noms
Styles

Autres ressources

Introduction au contrôle StyleSheet