EditorPartChrome 클래스

정의

개발자는 영역에서 선택한 컨트롤 섹션에 대해서만 렌더링을 재정의 EditorPart 할 수 있습니다 EditorZoneBase .

public ref class EditorPartChrome
public class EditorPartChrome
type EditorPartChrome = class
Public Class EditorPartChrome
상속
EditorPartChrome

예제

다음 코드 예제에서는 클래스를 사용 하 여 EditorPartChrome 영역에서 컨트롤의 기본 렌더링을 재정의 EditorPart 하는 방법을 보여 줍니다 EditorZoneBase .

코드 예제에는 다음 세 부분이 있습니다.

  • 웹 파트 페이지에서 표시 모드를 변경할 수 있는 사용자 컨트롤입니다.

  • 예제의 모든 컨트롤을 호스팅하는 웹 페이지입니다.

  • 사용자 지정 EditorPartChrome 클래스 및 EditorZoneBase 영역에 대한 소스 코드를 포함하는 클래스입니다.

코드 예제의 첫 번째 부분은 사용자 컨트롤입니다. 사용자 컨트롤의 소스 코드는 다른 항목에서 제공됩니다. 이 코드 예제가 작동하려면 연습 : 웹 파트 페이지의 표시 모드 변경 항목에서 사용자 컨트롤에 대한 .ascx 파일을 가져와서 이 코드 예제의 .aspx 페이지와 동일한 폴더에 배치해야 합니다.

예제의 두 번째 부분은 웹 페이지입니다. 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>

예제의 세 번째 부분에는 사용자 지정 편집기 파트 크롬 및 편집기 파트 영역의 구현이 포함되어 있습니다. MyEditorZone 확장 및 EditorZone 재정의 CreateEditorPartChrome 하여 사용자 지정 편집기 파트 Chrome을 반환합니다. 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은 영역에 포함된 각 웹 파트 컨트롤 또는 서버 컨트롤을 구성하는 주변 장치 UI(사용자 인터페이스) 요소를 나타냅니다. 컨트롤의 크롬에는 테두리, 제목 표시줄 및 제목 표시줄 내에 표시되는 아이콘, 제목 텍스트 및 동사 메뉴가 포함됩니다. 크롬의 모양은 영역 수준에서 설정되며 영역의 모든 컨트롤에 적용됩니다.

웹 파트 컨트롤 집합은 클래스를 EditorPartChrome 사용하여 컨트롤에 대한 크롬을 EditorPart 렌더링합니다. 또한 이 클래스는 개발자가 영역에서 컨트롤 EditorPart 의 렌더링을 사용자 지정할 수 있는 EditorZoneBase 방법을 제공합니다. 예를 들어 영역에 정의된 특정 스타일 특성을 사용자 지정하도록 메서드를 재정 CreateEditorPartChromeStyle 의할 EditorZoneBase 수 있습니다.

EditorPartChrome 클래스에는 컨트롤 렌더링을 재정의 EditorPart 하려는 경우에 유용한 몇 가지 중요한 메서드가 포함되어 있습니다. 하나는 사용자 지정 클래스의 EditorPartChrome 메서드를 재정 CreateEditorPartChrome 의하여 사용자 지정 EditorZoneBase 개체의 EditorPartChrome 인스턴스를 만들 때 사용하는 생성자입니다. 또 다른 유용한 방법은 RenderPartContents 머리글, 바닥글 및 제목 표시줄과 같은 Chrome 요소와 달리 영역에서 컨트롤의 콘텐츠 영역 렌더링을 제어하는 데 사용할 수 있는 방법입니다. 마지막으로, 컨트롤 렌더링의 모든 측면에 대한 완전한 프로그래밍 방식 제어를 EditorPart 원하는 경우 메서드를 재정의할 RenderEditorPart 수 있습니다.

상속자 참고

클래스에서 상속하는 EditorPartChrome 경우 사용자 지정된 클래스를 반환하기 위해 사용자 지정된 EditorZoneEditorPartChrome 영역을 만들어야 합니다. 이 클래스 개요의 예제 섹션에서는 사용자 EditorZone 지정된 클래스를 반환하는 사용자 지정 EditorPartChrome 영역을 만드는 방법을 보여 줍니다.

생성자

Name Description
EditorPartChrome(EditorZoneBase)

EditorPartChrome 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
Zone

연결된 영역에 대한 참조를 EditorZoneBase 가져옵니다.

메서드

Name Description
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)

적용 대상