IStyleSheet インターフェイス

定義

スタイル ルールの作成をサポートするためにクラスが実装する必要があるメソッドを定義します。

public interface class IStyleSheet
public interface IStyleSheet
type IStyleSheet = interface
Public Interface IStyleSheet

次のコード例では、HeaderIStyleSheet実装を使用して、プログラムで新しいスタイル ルールを作成し、カスタム Style オブジェクトを登録する方法を示します。

この例の最初の部分では、カスタム Style オブジェクト ( labelStyle) が作成され、現在の場所 (URL) に登録されます。 次に、 label1 ラベルは MergeStyle メソッドを呼び出して、 labelStyle スタイルが label1 ラベルに適用されるようにします。

この例の 2 番目の部分では、別のカスタム Style オブジェクト ( bodyStyle) を定義し、そのプロパティを設定して新しいスタイル ルールを作成します。

Note

このクラスは、主にカスタム実装を作成する開発者を対象としています。 この例では、.NET Framework によって提供される実装を示します。

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>    
<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="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 xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>
<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.";
    }
}

注釈

このインターフェイスを実装するクラスは、それを使用してスタイル ルールの作成をサポートできます。

カスケード スタイル シートの作成方法と登録方法をカスタマイズするには、このインターフェイスを実装するクラスを作成する必要があります。

HtmlHead クラスは、Header プロパティを介して ASP.NET で使用するために、このインターフェイスを実装します。

Note

非同期ポストバック中にプログラムでスタイルまたはスタイル ルールを追加または変更することはサポートされていません。 ASP.NET Web ページに AJAX 機能を追加すると、非同期ポストバックによってページ全体が更新されずにページの領域が更新されます。 詳細については、「 Microsoft Ajax の概要」を参照してください。

メソッド

名前 説明
CreateStyleRule(Style, IUrlResolutionService, String)

クラスによって実装される場合は、指定したドキュメント言語要素型 (セレクター) のスタイル ルールを作成します。

RegisterStyle(Style, IUrlResolutionService)

クラスによって実装された場合は、Web ページの <head> セクションの埋め込みスタイル シートに新しいスタイル ルールを追加します。

適用対象

こちらもご覧ください