StyleSheet クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)
構文
Public Class StyleSheet Inherits MobileControl
public class StyleSheet : MobileControl
public class StyleSheet extends MobileControl
public class StyleSheet extends MobileControl
StyleSheet コントロールには、スタイル オブジェクトをいくつでも追加できます。また、Style クラスから継承した特殊なスタイル オブジェクトの追加も可能です。スタイル オブジェクトは、一意の名前のプロパティを持っている必要があります。こうすると、同じページの他のコントロールを Name プロパティで参照できます。これ自体が表示されることはありません。
また、外部スタイル シートも使用できるので、いくつかのページで同じ外部スタイル シートを共有することも可能です。スタイルの詳細については、<Style> 要素 要素と Styles のトピックを参照してください。
メモ |
---|
StyleSheet コントロールは、それ自体のスタイル属性を無視します。スタイル属性を StyleSheet コントロール自体に設定しても、StyleSheet コントロール内の子として含まれるスタイルには影響ありません。 |
Page_Load イベントの実行中に Style プロパティを StyleSheet コントロールに追加する方法の例を次に示します。
<%@ 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 > <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>
System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.StyleSheet
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- StyleSheet クラスのページへのリンク