IStyleSheetとは? わかりやすく解説

IStyleSheet インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

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.";
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

IStyleSheet メソッド


IStyleSheet メンバ




英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「IStyleSheet」の関連用語

IStyleSheetのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



IStyleSheetのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS