EditorPartChrome クラス
アセンブリ: System.Web (system.web.dll 内)


クロムとは、各 Web パーツ コントロールまたはゾーン内に含まれるサーバー コントロールの周囲に表示する周辺ユーザー インターフェイス (UI: User Interface) 要素のことです。コントロールのクロムには、境界線、タイトル バー、アイコン、タイトル テキストがあり、さらにはタイトル バーに表示される動詞メニューも含まれます。クロムの外観は、ゾーン レベルに対して設定され、ゾーン内のすべてのコントロールに適用されます。
Web パーツ コントロール セットは、EditorPartChrome クラスを使用して EditorPart コントロールのクロムを表示します。また、このクラスを使用すると、開発者は EditorZoneBase ゾーン内の任意の EditorPart コントロールの表示をカスタマイズできます。たとえば、CreateEditorPartChromeStyle メソッドをオーバーライドして、EditorZoneBase ゾーンで定義されている特定のスタイル属性の一部をカスタマイズできます。
EditorPartChrome クラスには、EditorPart コントロールの表示をオーバーライドする場合に役立つ複数の重要なメソッドが含まれています。1 つは、EditorPartChrome コンストラクタです。このコンストラクタは、カスタム EditorZoneBase クラスの CreateEditorPartChrome メソッドをオーバーライドして、カスタム EditorPartChrome オブジェクトのインスタンスを作成する場合に使用します。また RenderPartContents メソッドも役立ちます。このメソッドは、 ヘッダー、フッター、タイトル バーなどのクロム要素とは異なるように、ゾーン内の コントロールのコンテンツ領域の表示を制御する場合に使用できます。最後に、EditorPart コントロールの表示のあらゆる要素をプログラムで完全に制御する場合には、RenderEditorPart メソッドをオーバーライドできます。
実装時の注意 EditorPartChrome クラスから継承する場合、カスタマイズした EditorPartChrome クラスを返すためにカスタマイズした EditorZone ゾーンを作成する必要があります。このクラスの概要の「使用例」は、カスタマイズした EditorZone ゾーンを作成し、カスタマイズした EditorPartChrome クラスを返す方法を示しています。
EditorPartChrome クラスを使用して EditorZoneBase ゾーンの EditorPart コントロールの既定の表示をオーバーライドする方法を次のコード例に示します。
コード例の最初の部分は、ユーザー コントロールです。ユーザー コントロールのソース コードは、別のトピックのものを使用しています。このコード例を実行するには、チュートリアル : Web パーツ ページでの表示モードの変更 のトピックに記載されているユーザー コントロールの .ascx ファイルを、このコード例に示されている .ascx ページと同じフォルダに配置する必要があります。
コード例の 2 番目の部分は Web ページです。コンパイルしたコンポーネントとタグ プリフィックスを登録するため、ファイルの先頭近くには、Register ディレクティブが存在します。また、このページは、<aspSample:MyEditorZone> 要素を使用してカスタム エディタ ゾーンを参照しています。
<%@ Page Language="VB" %> <%@ register tagprefix="aspSample" Namespace="Samples.AspNet.VB.Controls" %> <%@ Register TagPrefix="uc1" TagName="DisplayModeMenuVB" Src="~/DisplayModeMenuVB.ascx" %> <html> <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>
<%@ Page Language="C#" %> <%@ register tagprefix="aspSample" Namespace="Samples.AspNet.CS.Controls" %> <%@ Register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="~/DisplayModeMenuCS.ascx" %> <html> <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>
コード例の 3 番目の部分は、カスタムのエディタ パーツ クロムとエディタ パーツ ゾーンの実装を含んでいます。MyEditorZone は EditorZone を拡張し、CreateEditorPartChrome をオーバーライドして、カスタムのエディタ パーツ クロムを返します。MyEditorPartChrome は、CreateEditorPartChromeStyle メソッドのエディタ パーツ コントロールの背景色を変更します。ゾーンの背景色は PerformPreRender メソッドで変更され、RenderPartContents メソッドでエディタ パーツにテキストが追加されます。
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
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); } } }


System.Web.UI.WebControls.WebParts.EditorPartChrome


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- EditorPartChrome クラスのページへのリンク