IStyleSheet インターフェイス
アセンブリ: System.Web (system.web.dll 内)


このインターフェイスを実装するクラスは、このインターフェイスを使用してスタイル ルールの作成をサポートできます。
カスケード スタイル シートの作成と登録の方法をカスタマイズするには、このインターフェイスを実装するクラスを作成する必要があります。
HtmlHead クラスは、ASP.NET が Header プロパティ経由で使用できるようにこのインターフェイスを実装しています。

IStyleSheet の Header 実装を使用して、プログラムによって新しいスタイル ルールを作成し、カスタム Style オブジェクトを登録するコード例を次に示します。
コード例の最初の部分では、カスタム Style オブジェクトである labelStyle を作成し、現在の場所 (URL) に登録します。次に、label1 ラベルが MergeStyle メソッドを呼び出し、labelStyle スタイルを label1 ラベルに適用します。
2 番目の部分では、もう 1 つのカスタム Style オブジェクトである bodyStyle を定義し、プロパティを設定して、新しいスタイル ルールを作成します。
![]() |
---|
このクラスは、主に、カスタム実装を作成する開発者が使用するためのものです。この例では、.NET Framework が提供する実装を示しています。 |
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="istylesheetvb.aspx.vb" Inherits="istylesheetvb" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head id="head1" runat="server" /> <body> <form id="form1" runat="server"> <h1>IStyleSheet Example</h1> <asp:Label id="label1" runat="server"> </asp:Label> <br /><br /> <asp:Label id="label2" runat="server"> </asp:Label> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="istylesheetcs.aspx.cs" Inherits="istylesheetcs" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head id="head1" runat="server" /> <body> <form id="form1" runat="server"> <h1>IStyleSheet Example</h1> <asp:Label id="label1" runat="server"> </asp:Label> <br /><br /> <asp:Label id="label2" runat="server"> </asp:Label> </form> </body> </html>
前の例の Web ページに対する分離コード ファイルを次に示します。
public partial class istylesheetcs : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Create a Style object to hold style rules to apply to a Label control. Style labelStyle = new Style(); labelStyle.ForeColor = System.Drawing.Color.DarkRed; labelStyle.BorderColor = System.Drawing.Color.DarkBlue; labelStyle.BorderWidth = 2; // Register the Style object so that it can be merged with // the Style object of the controls that use it. Page.Header.StyleSheet.RegisterStyle(labelStyle, null); // Merge the labelCssStyle style with the label1 control's // style settings. label1.MergeStyle(labelStyle); label1.Text = "This is what the labelCssStyle looks like."; // Create a Style object for the <BODY> section of the Web page. Style bodyStyle = new Style(); bodyStyle.ForeColor = System.Drawing.Color.Blue; bodyStyle.BackColor = System.Drawing.Color.LightGray; // Add the style to the header of the current page. Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "BODY"); // Add text to the label2 control to see the label without // the labelStyle applied to it. label2.Text = "This is what the bodyStyle looks like."; } }

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


IStyleSheet メソッド

名前 | 説明 | |
---|---|---|
![]() | CreateStyleRule | クラスによって実装された場合は、指定されたドキュメント言語要素型つまりセレクタに対してスタイル ルールを作成します。 |
![]() | RegisterStyle | クラスによって実装された場合、Web ページの <head> セクション内の埋め込みスタイル シートに新しいスタイル ルールを追加します。 |

IStyleSheet メンバ
- IStyleSheetのページへのリンク