IStyleSheet インターフェイス

定義

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

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

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

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

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

注意

このクラスは、主にカスタム実装を作成する開発者を対象としています。 この例では、.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 、 プロパティを介して ASP.NET 使用するために、このインターフェイスを Header 実装します。

注意

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

メソッド

CreateStyleRule(Style, IUrlResolutionService, String)

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

RegisterStyle(Style, IUrlResolutionService)

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

適用対象

こちらもご覧ください