EditorPartChrome クラス

定義

開発者は、EditorPart ゾーン内のEditorZoneBase コントロールの選択したセクションのレンダリングのみをオーバーライドできます。

public ref class EditorPartChrome
public class EditorPartChrome
type EditorPartChrome = class
Public Class EditorPartChrome
継承
EditorPartChrome

次のコード例では、EditorPartChrome クラスを使用して、EditorPart ゾーン内のEditorZoneBase コントロールの既定のレンダリングをオーバーライドする方法を示します。

このコード例には、次の 3 つの部分があります。

  • Web パーツ ページの表示モードを変更できるユーザー コントロール。

  • この例のすべてのコントロールをホストする Web ページ。

  • カスタム EditorPartChrome クラスと EditorZoneBase ゾーンのソース コードを含むクラス。

コード例の最初の部分は、ユーザー コントロールです。 ユーザー コントロールのソース コードは、別のトピックから取得されます。 このコード例を機能させるには、「 チュートリアル: Web パーツ ページでの表示モードの変更 」トピックからユーザー コントロールの .ascx ファイルを取得し、このコード例の .aspx ページと同じフォルダーにファイルを配置する必要があります。

この例の 2 番目の部分は Web ページです。 コンパイル済みコンポーネントとタグ プレフィックスを登録するために、ファイルの先頭付近に Register ディレクティブがあることに注意してください。 また、ページは要素 <aspSample:MyEditorZone>を使用してカスタム エディター ゾーンを参照します。

<%@ Page Language="C#" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" %>
<%@ Register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="~/DisplayModeMenuCS.ascx" %>
<!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>Web Parts Page</title>
</head>
<body>
  <h1>Web Parts Demonstration Page</h1>
  <form runat="server" id="form1">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<uc1:DisplayModeMenuCS runat="server" ID="DisplayModeMenu" />
  <br />
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td valign="top">
    <asp:webpartzone id="SideBarZone" runat="server" 
        headertext="Sidebar">
        <zonetemplate>
        </zonetemplate>
      </asp:webpartzone>
      <aspSample:MyEditorZone ID="EditorZone1" runat="server">
      <ZoneTemplate>
        <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
          runat="server" />
        <asp:LayoutEditorPart ID="LayoutEditorPart1" 
          runat="server" />
      </ZoneTemplate>
    </aspSample:MyEditorZone>
      </td>
      <td valign="top">
    <asp:webpartzone id="MainZone" runat="server" headertext="Main">
         <zonetemplate>
        <asp:label id="contentPart" runat="server" title="Content">
              <h2>Welcome to My Home Page</h2>
              <p>Use links to visit my favorite sites!</p>
            </asp:label>
         </zonetemplate>
       </asp:webpartzone>
      </td>
      <td valign="top">
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls" %>
<%@ Register TagPrefix="uc1" TagName="DisplayModeMenuVB" Src="~/DisplayModeMenuVB.ascx" %>
<!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>Web Parts Page</title>
</head>
<body>
  <h1>Web Parts Demonstration Page</h1>
  <form runat="server" id="form1">
<asp:webpartmanager id="WebPartManager1" runat="server" />
<uc1:DisplayModeMenuVB runat="server" ID="DisplayModeMenu" />
  <br />
  <table cellspacing="0" cellpadding="0" border="0">
    <tr>
      <td valign="top">
    <asp:webpartzone id="SideBarZone" runat="server" 
        headertext="Sidebar">
        <zonetemplate>
        </zonetemplate>
      </asp:webpartzone>
      <aspSample:MyEditorZone ID="EditorZone1" runat="server">
      <ZoneTemplate>
        <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
          runat="server" />
        <asp:LayoutEditorPart ID="LayoutEditorPart1" 
          runat="server" />
      </ZoneTemplate>
    </aspSample:MyEditorZone>
      </td>
      <td valign="top">
    <asp:webpartzone id="MainZone" runat="server" headertext="Main">
         <zonetemplate>
        <asp:label id="contentPart" runat="server" title="Content">
              <h2>Welcome to My Home Page</h2>
              <p>Use links to visit my favorite sites!</p>
            </asp:label>
         </zonetemplate>
       </asp:webpartzone>
      </td>
      <td valign="top">
      </td>
    </tr>
  </table>
  </form>
</body>
</html>

この例の 3 番目の部分には、カスタム エディター パーツクロムとエディター パーツ ゾーンの実装が含まれています。 MyEditorZoneEditorZone を拡張し、カスタム エディター パーツのクロムを返すように CreateEditorPartChrome をオーバーライドします。 MyEditorPartChrome は、 CreateEditorPartChromeStyle メソッドのエディター パーツ コントロールの背景色を変更します。 PerformPreRender メソッドではゾーンの背景色が変更され、テキストは RenderPartContents メソッドのエディター パーツに追加されます。

namespace Samples.AspNet.CS.Controls
{

    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    public class MyEditorPartChrome : EditorPartChrome
    {
        public MyEditorPartChrome(EditorZoneBase zone)
            : base(zone)
        {
        }
        
        protected override Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType)
        {
            Style editorStyle = base.CreateEditorPartChromeStyle(editorPart, chromeType);
            editorStyle.BackColor = Color.Bisque;
            return editorStyle;
        }

        public override void PerformPreRender()
        {
            Style zoneStyle = new Style();
            zoneStyle.BackColor = Color.Cornsilk;

            Zone.Page.Header.StyleSheet.RegisterStyle(zoneStyle, null);
            Zone.MergeStyle(zoneStyle);
        }

        protected override void RenderPartContents(HtmlTextWriter writer, EditorPart editorPart)
        {
            writer.AddStyleAttribute("color", "red");
            writer.RenderBeginTag("p");
            writer.Write("Apply all changes");
            writer.RenderEndTag();
            editorPart.RenderControl(writer);
        }

        public override void RenderEditorPart(HtmlTextWriter writer, EditorPart editorPart)
        {
            base.RenderEditorPart(writer, editorPart);
        }
    }

    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    public class MyEditorZone : EditorZone
    {
        protected override EditorPartChrome CreateEditorPartChrome()
        {
            return new MyEditorPartChrome(this);
        }
    }
}
Namespace Samples.AspNet.VB.Controls


    <AspNetHostingPermission(SecurityAction.Demand, _
      Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
      Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class MyEditorPartChrome
        Inherits EditorPartChrome

        Public Sub New(ByVal zone As EditorZoneBase)
            MyBase.New(zone)
        End Sub

        Protected Overrides Function CreateEditorPartChromeStyle(ByVal editorPart As System.Web.UI.WebControls.WebParts.EditorPart, ByVal chromeType As System.Web.UI.WebControls.WebParts.PartChromeType) As System.Web.UI.WebControls.Style
            Dim editorStyle As Style
            editorStyle = MyBase.CreateEditorPartChromeStyle(editorPart, chromeType)
            editorStyle.BackColor = Drawing.Color.Bisque
            Return editorStyle
        End Function

        Public Overrides Sub PerformPreRender()
            Dim zoneStyle As Style = New Style
            zoneStyle.BackColor = Drawing.Color.Cornsilk

            Zone.Page.Header.StyleSheet.RegisterStyle(zoneStyle, Nothing)
            Zone.MergeStyle(zoneStyle)
        End Sub

        Protected Overrides Sub RenderPartContents(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal editorPart As System.Web.UI.WebControls.WebParts.EditorPart)
            writer.AddStyleAttribute("color", "red")
            writer.RenderBeginTag("p")
            writer.Write("Apply all changes")
            writer.RenderEndTag()
            editorPart.RenderControl(writer)
        End Sub

        Public Overrides Sub RenderEditorPart(ByVal writer As System.Web.UI.HtmlTextWriter, ByVal editorPart As System.Web.UI.WebControls.WebParts.EditorPart)
            MyBase.RenderEditorPart(writer, editorPart)
        End Sub
    End Class


    <AspNetHostingPermission(SecurityAction.Demand, _
      Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
      Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class MyEditorZone
        Inherits EditorZone

        Protected Overrides Function CreateEditorPartChrome() As System.Web.UI.WebControls.WebParts.EditorPartChrome
            Return New MyEditorPartChrome(Me)
        End Function
    End Class
End Namespace

注釈

Chrome は、ゾーンに含まれる各 Web パーツ コントロールまたはサーバー コントロールをフレームに収める周辺機器ユーザー インターフェイス (UI) 要素を指します。 コントロールのクロムには、境界線、タイトル バー、およびタイトル バー内に表示されるアイコン、タイトル テキスト、動詞メニューが含まれます。 クロムの外観はゾーン レベルで設定され、ゾーン内のすべてのコントロールに適用されます。

Web パーツ コントロール セットは、 EditorPartChrome クラスを使用して、 EditorPart コントロールのクロムをレンダリングします。 さらに、このクラスは、開発者がEditorPart ゾーン内の任意のEditorZoneBase コントロールのレンダリングをカスタマイズする方法を提供します。 たとえば、 CreateEditorPartChromeStyle メソッドをオーバーライドして、 EditorZoneBase ゾーンで定義されている特定のスタイル属性をカスタマイズできます。

EditorPartChrome クラスには、EditorPart コントロールのレンダリングをオーバーライドする場合に便利ないくつかの重要なメソッドが含まれています。 1 つは EditorPartChrome コンストラクターです。カスタム CreateEditorPartChrome クラスのEditorZoneBase メソッドをオーバーライドして、カスタム EditorPartChrome オブジェクトのインスタンスを作成するときに使用します。 もう 1 つの便利な方法は、 RenderPartContents メソッドです。これは、(ヘッダー、フッター、タイトル バーなどのクロム要素ではなく) ゾーン内のコントロールのコンテンツ領域のレンダリングを制御するために使用できます。 最後に、 EditorPart コントロールのレンダリングのすべての側面をプログラムで完全に制御する場合は、 RenderEditorPart メソッドをオーバーライドできます。

注意 (継承者)

EditorPartChrome クラスから継承する場合は、カスタマイズしたEditorZone ゾーンを作成して、カスタマイズしたEditorPartChrome クラスを返す必要があります。 このクラスの概要の例セクションでは、カスタマイズされた EditorZone ゾーンを作成して、カスタマイズされた EditorPartChrome クラスを返す方法を示します

コンストラクター

名前 説明
EditorPartChrome(EditorZoneBase)

EditorPartChrome クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Zone

関連付けられている EditorZoneBase ゾーンへの参照を取得します。

メソッド

名前 説明
CreateEditorPartChromeStyle(EditorPart, PartChromeType)

EditorPart オブジェクトによってレンダリングされる各EditorPartChrome コントロールのスタイル属性を提供するスタイル オブジェクトを作成します。

Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
PerformPreRender()

EditorPart コントロールをレンダリングする前に実行する必要があるタスクを実行します。

RenderEditorPart(HtmlTextWriter, EditorPart)

すべてのセクションを含む完全な EditorPart コントロールをレンダリングします。

RenderPartContents(HtmlTextWriter, EditorPart)

ヘッダーとフッターを除く、 EditorPart コントロールのメイン コンテンツ領域をレンダリングします。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象