Style クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)


基本クラスとしての Style には、すべてのモバイル コントロールに共通するスタイル特性が格納されます。Style クラスから継承されたクラスには、それらに関連付けられているコントロールに固有の付加的なスタイル特性が格納されます。
モバイル コントロールでサポートされるデバイスは多岐にわたるため、どのスタイル プロパティもあくまでアドバイザリとしてのプロパティです。これらのプロパティを実装すべきかどうかは、対象デバイスの機能によって異なります。

3 つのユーザー定義スタイルを 1 つの StyleSheet オブジェクトに整理する例を次に示します。この 3 つのスタイルに対応する 3 つの値が SelectionList オブジェクトに保持されます。OnClick コマンド イベントが発生すると、SelectStyle 関数が呼び出されます。この関数は、TextView オブジェクトの StyleReference プロパティを変更します。
<%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script runat="server"> 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 > <body> <mobile:StyleSheet id="StyleSheet1" runat="server"> <mobile:Style font-size="Large" font-name="Arial" font-bold="true" forecolor="red" font-italic="true" backcolor="#E0E0E0" wrapping="wrap" name="Style1"> </mobile:Style> <mobile:Style font-size="Normal" font-name="Arial" font-bold="false" forecolor="Blue" font-italic="true" backcolor="blue" wrapping="NoWrap" name="Style2"> </mobile:Style> <mobile:Style font-size="Small" font-name="Arial Narrow" font-bold="false" forecolor="Green" font-italic="false" backcolor="Green" wrapping="NoWrap" name="Style3"> </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" %> <script runat="server"> 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 font-size="Large" font-name="Arial" font-bold="true" forecolor="red" font-italic="true" backcolor="#E0E0E0" wrapping="wrap" name="Style1"> </mobile:Style> <mobile:Style font-size="Normal" font-name="Arial" font-bold="false" forecolor="Blue" font-italic="true" backcolor="blue" wrapping="NoWrap" name="Style2"> </mobile:Style> <mobile:Style font-size="Small" font-name="Arial Narrow" font-bold="false" forecolor="Green" font-italic="false" backcolor="Green" wrapping="NoWrap" name="Style3"> </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 runat="server" Text="Select Style" OnClick="SelectStyle" /> </mobile:form> </body> </html>


System.Web.UI.MobileControls.Style
System.Web.UI.MobileControls.PagerStyle


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Style クラス
アセンブリ: System.Web (system.web.dll 内)


Style クラスは、Web サーバー コントロールの外観を制御するプロパティをカプセル化し、複数の Web サーバー コントロールに適用して共通の外観を指定できます。コントロールの背景色とフォントの色を指定するには、BackColor プロパティと ForeColor プロパティをそれぞれ設定します。境界線を表示できるコントロールで、境界線の幅、境界線スタイル、および境界線の色を制御するには、BorderWidth、BorderStyle、BorderColor の各プロパティをそれぞれ設定します。Web サーバー コントロールのサイズは、Height プロパティと Width プロパティを使用して指定することもできます。

この例では、Style オブジェクトを使用して、複数のコントロールのスタイル プロパティを一度に変更する方法を示します。Style プロパティのいずれかの値を変更するたびに、各コントロールはその ApplyStyle メソッドを呼び出す必要があります。含まれているすべてのコントロールが、ここに示すすべてのプロパティをサポートするわけではありません。特定のプロパティをサポートしないコントロールの場合、そのプロパティの値が変更されても、そのコントロールの外観は変わりません。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page language="VB" AutoEventWireup="true" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Data" %> <html> <head> <script runat="server"> Private Dim primaryStyle As New Style() Sub Page_Load(sender As Object, e As System.EventArgs) If Not Page.IsPostBack Then ' Add data to the borderColorList, ' backColorList, and foreColorList controls. Dim colors As New ListItemCollection() colors.Add(Color.Black.Name) colors.Add(Color.Blue.Name) colors.Add(Color.Green.Name) colors.Add(Color.Orange.Name) colors.Add(Color.Purple.Name) colors.Add(Color.Red.Name) colors.Add(Color.White.Name) colors.Add(Color.Yellow.Name) borderColorList.DataSource = colors borderColorList.DataBind() backColorList.DataSource = colors backColorList.DataBind() foreColorList.DataSource = colors foreColorList.DataBind() ' Add data to the borderStyleList control. Dim styles As New ListItemCollection() Dim styleType As Type = GetType(BorderStyle) Dim s As String For Each s in [Enum].GetNames(styleType) styles.Add(s) Next s borderStyleList.DataSource = styles borderStyleList.DataBind() ' Add data to the borderWidthList control. Dim widths As New ListItemCollection() Dim i As Integer for i = 0 To 10 widths.Add(i.ToString() & "px") Next i borderWidthList.DataSource = widths borderWidthList.DataBind() ' Add data to the fontNameList control. Dim names As New ListItemCollection() names.Add("Arial") names.Add("Courier") names.Add("Garamond") names.Add("Time New Roman") names.Add("Verdana") fontNameList.DataSource = names fontNameList.DataBind() ' Add data to the fontSizeList control. Dim fontSizes As New ListItemCollection() fontSizes.Add("Small") fontSizes.Add("Medium") fontSizes.Add("Large") fontSizes.Add("10pt") fontSizes.Add("14pt") fontSizes.Add("20pt") fontSizeList.DataSource = fontSizes fontSizeList.DataBind() ' Set primaryStyle as the style for each control. Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End If End Sub Sub ChangeBorderColor(sender As Object, e As System.EventArgs) primaryStyle.BorderColor = _ Color.FromName(borderColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBackColor(sender As Object, e As System.EventArgs) primaryStyle.BackColor = _ Color.FromName(backColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeForeColor(sender As Object, e As System.EventArgs) primaryStyle.ForeColor = _ Color.FromName(foreColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBorderStyle(sender As Object, e As System.EventArgs) primaryStyle.BorderStyle = _ CType([Enum].Parse(GetType(BorderStyle), _ borderStyleList.SelectedItem.Text), BorderStyle) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBorderWidth(sender As Object, e As System.EventArgs) primaryStyle.BorderWidth = _ Unit.Parse(borderWidthList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeFont(sender As Object, e As System.EventArgs) primaryStyle.Font.Name = _ fontNameList.SelectedItem.Text Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeFontSize(sender As Object, e As System.EventArgs) primaryStyle.Font.Size = _ FontUnit.Parse(fontSizeList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub </script> </head> <body> <form id="Form1" runat="server"> <table cellPadding="6" border="0"> <tr> <td> <asp:label id="Label1" Text="Border Properties Example" Runat="server"> <center><br>Label Styles</center> </asp:label> </td> <td> <asp:button id="Button1" runat="server" Text="Button Styles"> </asp:button> </td> <td> <asp:listbox id="ListBox1" Runat="server"> <asp:ListItem Value="0" Text="List Item 0"> </asp:ListItem> <asp:ListItem Value="1" Text="List Item 1"> </asp:ListItem> <asp:ListItem Value="2" Text="List Item 2"> </asp:ListItem> </asp:listbox> </td> <td> <asp:textbox id="TextBox1" Text="TextBox Styles" Runat="server"> </asp:textbox> </td> <td> <asp:table id="Table1" Runat="server"> <asp:TableRow> <asp:TableCell Text="(0,0)"></asp:TableCell> <asp:TableCell Text="(0,1)"></asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell Text="(1,0)"></asp:TableCell> <asp:TableCell Text="(1,1)"></asp:TableCell> </asp:TableRow> </asp:table> </td> </tr> <tr> <td> <asp:Label Runat="server" Text="Border Color:"> </asp:Label> <asp:dropdownlist id="borderColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Style:"> </asp:Label> <asp:dropdownlist id="borderStyleList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderStyle"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Width"> </asp:Label> <asp:dropdownlist id="borderWidthList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderWidth"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Back Color:"> </asp:Label> <asp:dropdownlist id="backColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBackColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Foreground Color:"> </asp:Label> <asp:dropdownlist id="foreColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeForeColor"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Font Name:"> </asp:Label> <asp:dropdownlist id="fontNameList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFont"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Font Size:"> </asp:Label> <asp:dropdownlist id="fontSizeList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFontSize"> </asp:dropdownlist> </td> </tr> </table> </form> </body> </html>
<%@ Page language="C#" AutoEventWireup="true" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Data" %> <html> <head> <script runat="server"> private Style primaryStyle = new Style(); void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // Add data to the borderColorList, // backColorList, and foreColorList controls. ListItemCollection colors = new ListItemCollection(); colors.Add(Color.Black.Name); colors.Add(Color.Blue.Name); colors.Add(Color.Green.Name); colors.Add(Color.Orange.Name); colors.Add(Color.Purple.Name); colors.Add(Color.Red.Name); colors.Add(Color.White.Name); colors.Add(Color.Yellow.Name); borderColorList.DataSource = colors; borderColorList.DataBind(); backColorList.DataSource = colors; backColorList.DataBind(); foreColorList.DataSource = colors; foreColorList.DataBind(); // Add data to the borderStyleList control. ListItemCollection styles = new ListItemCollection(); Type styleType = typeof(BorderStyle); foreach (string s in Enum.GetNames(styleType)) { styles.Add(s); } borderStyleList.DataSource = styles; borderStyleList.DataBind(); // Add data to the borderWidthList control. ListItemCollection widths = new ListItemCollection(); for (int i = 0; i < 11; i++) { widths.Add(i.ToString() + "px"); } borderWidthList.DataSource = widths; borderWidthList.DataBind(); // Add data to the fontNameList control. ListItemCollection names = new ListItemCollection(); names.Add("Arial"); names.Add("Courier"); names.Add("Garamond"); names.Add("Time New Roman"); names.Add("Verdana"); fontNameList.DataSource = names; fontNameList.DataBind(); // Add data to the fontSizeList control. ListItemCollection fontSizes = new ListItemCollection(); fontSizes.Add("Small"); fontSizes.Add("Medium"); fontSizes.Add("Large"); fontSizes.Add("10pt"); fontSizes.Add("14pt"); fontSizes.Add("20pt"); fontSizeList.DataSource = fontSizes; fontSizeList.DataBind(); //Set primaryStyle as the style for each control. Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } } void ChangeBorderColor(object sender, System.EventArgs e) { primaryStyle.BorderColor = Color.FromName(borderColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBackColor(object sender, System.EventArgs e) { primaryStyle.BackColor = Color.FromName(backColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeForeColor(object sender, System.EventArgs e) { primaryStyle.ForeColor = Color.FromName(foreColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBorderStyle(object sender, System.EventArgs e) { primaryStyle.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), borderStyleList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBorderWidth(object sender, System.EventArgs e) { primaryStyle.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeFont(object sender, System.EventArgs e) { primaryStyle.Font.Name = fontNameList.SelectedItem.Text; Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeFontSize(object sender, System.EventArgs e) { primaryStyle.Font.Size = FontUnit.Parse(fontSizeList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } </script> </head> <body> <form id="Form1" runat="server"> <table cellPadding="6" border="0"> <tr> <td> <asp:label id="Label1" Text="Border Properties Example" Runat="server"> <center><br>Label Styles</center> </asp:label> </td> <td> <asp:button id="Button1" runat="server" Text="Button Styles"> </asp:button> </td> <td> <asp:listbox id="ListBox1" Runat="server"> <asp:ListItem Value="0" Text="List Item 0"> </asp:ListItem> <asp:ListItem Value="1" Text="List Item 1"> </asp:ListItem> <asp:ListItem Value="2" Text="List Item 2"> </asp:ListItem> </asp:listbox> </td> <td> <asp:textbox id="TextBox1" Text="TextBox Styles" Runat="server"> </asp:textbox> </td> <td> <asp:table id="Table1" Runat="server"> <asp:TableRow> <asp:TableCell Text="(0,0)"></asp:TableCell> <asp:TableCell Text="(0,1)"></asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell Text="(1,0)"></asp:TableCell> <asp:TableCell Text="(1,1)"></asp:TableCell> </asp:TableRow> </asp:table> </td> </tr> <tr> <td> <asp:Label Runat="server" Text="Border Color:"> </asp:Label> <asp:dropdownlist id="borderColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Style:"> </asp:Label> <asp:dropdownlist id="borderStyleList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderStyle"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Width"> </asp:Label> <asp:dropdownlist id="borderWidthList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderWidth"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Back Color:"> </asp:Label> <asp:dropdownlist id="backColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBackColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Foreground Color:"> </asp:Label> <asp:dropdownlist id="foreColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeForeColor"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Font Name:"> </asp:Label> <asp:dropdownlist id="fontNameList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFont"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Font Size:"> </asp:Label> <asp:dropdownlist id="fontSizeList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFontSize"> </asp:dropdownlist> </td> </tr> </table> </form> </body> </html>


System.MarshalByRefObject
System.ComponentModel.Component
System.Web.UI.WebControls.Style
派生クラス


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Style クラスのページへのリンク