組合管理要套用到其他控制項的樣式。
命名空間: System.Web.UI.MobileControls
組件: System.Web.Mobile (在 system.web.mobile.dll 中)
語法
'宣告
Public Class StyleSheet
Inherits MobileControl
'用途
Dim instance As StyleSheet
public class StyleSheet : MobileControl
public ref class StyleSheet : public MobileControl
public class StyleSheet extends MobileControl
public class StyleSheet extends MobileControl
備註
StyleSheet 控制項可以包含任意數目的樣式物件,或更多從 Style 類別 (Class) 繼承的特別樣式物件。這些物件應該具有唯一的 Name 屬性。然後您可以依控制項的 Name 屬性 (Property) 參考相同頁面上的其他控制項。這個類別沒有圖形表示。
網頁也可以使用外部樣式表,且多個網頁可以共用相同的外部樣式表。如需樣式的詳細資訊,請參閱 <Style> 項目 項目和 Styles 主題。
注意事項 |
|---|
StyleSheet 控制項會忽略本身的樣式屬性 (Attribute),對 StyleSheet 本身設定樣式屬性,不會對 StyleSheet 控制項中所包含做為子系的樣式產生作用。 |
範例
下列範例顯示如何在 Page_Load 事件期間,將樣式屬性加入至 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 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>
.NET Framework 安全性
- AspNetHostingPermission 用於裝載環境中的作業。要求值:LinkDemand,權限值:Minimal。
- AspNetHostingPermission 用於裝載環境中的作業。要求值:InheritanceDemand,權限值:Minimal。
繼承階層架構
System.Object
System.Web.UI.Control
System.Web.UI.MobileControls.MobileControl
System.Web.UI.MobileControls.StyleSheet
執行緒安全
這個型別的所有公用靜態成員 (即 Visual Basic 中的 Shared 成員) 都是安全執行緒。並非所有的執行個體成員均為安全執行緒。
平台
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 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。
版本資訊
.NET Framework
支援版本:2.0、1.1
請參閱
參考
StyleSheet 成員
System.Web.UI.MobileControls 命名空間
Styles
注意事項