다음을 통해 공유


WebPartChrome(WebPartZoneBase, WebPartManager) 생성자

정의

컨트롤의 새 인스턴스를 초기화합니다.

public:
 WebPartChrome(System::Web::UI::WebControls::WebParts::WebPartZoneBase ^ zone, System::Web::UI::WebControls::WebParts::WebPartManager ^ manager);
public WebPartChrome (System.Web.UI.WebControls.WebParts.WebPartZoneBase zone, System.Web.UI.WebControls.WebParts.WebPartManager manager);
new System.Web.UI.WebControls.WebParts.WebPartChrome : System.Web.UI.WebControls.WebParts.WebPartZoneBase * System.Web.UI.WebControls.WebParts.WebPartManager -> System.Web.UI.WebControls.WebParts.WebPartChrome
Public Sub New (zone As WebPartZoneBase, manager As WebPartManager)

매개 변수

zone
WebPartZoneBase

연결된 WebPartZoneBase 컨트롤입니다.

manager
WebPartManager

현재 페이지의 WebPartManager 컨트롤입니다.

예외

zone이(가) null인 경우

예제

다음 코드 예제에서는 두 가지를 보여 줍니다. 먼저 라는 MyZone파생 영역에서 메서드를 재정의하여 사용자 지정 클래스 MyWebPartChromeCreateWebPartChrome 새 인스턴스를 WebPartZoneBase 만듭니다. 둘째, 클래스의 MyWebPartChrome 생성자에서 클래스 내에서 사용할 수 있는 프라이빗 필드에 생성자의 매개 변수에 있는 개체를 할당합니다. 따라서 이 예제에서는 및 속성에 액세스할 수 있기 전에 생성자에서도 연결된 영역 및 WebPartManagerWebPartManager 개체에 Zone 액세스할 수 있는 방법을 제공합니다. 마지막으로 생성자가 작동하려면 메서드 선언의 일부로 기본 생성자도 호출해야 합니다.

다음 코드에는 두 개의 사용자 지정 클래스가 포함되어 있습니다. 이러한 컨트롤을 호스트하는 웹 페이지를 포함하여 예제를 실행하는 데 필요한 전체 코드는 클래스 개요 항목의 예제 섹션을 WebPartChrome 참조하세요.

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class MyZone : WebPartZone
  {
    private Boolean _renderVerbsInMenu;

    protected override WebPartChrome CreateWebPartChrome()
    {
      WebPartChrome theChrome = new MyWebPartChrome(this, 
        this.WebPartManager);
      if (RenderVerbsInMenu)
        this.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
      else
        this.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
      return theChrome;
    }

    public Boolean RenderVerbsInMenu
    {
      get { return _renderVerbsInMenu; }
      set { _renderVerbsInMenu = value; }
    }
  }

  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class MyWebPartChrome : WebPartChrome
  {
    WebPartZoneBase theZone;
    WebPartManager theManager;

    public MyWebPartChrome(WebPartZoneBase aZone, WebPartManager aManager) : 
      base(aZone, aManager)
    {
      theZone = aZone;
      theManager = aManager;
    }

    protected override WebPartVerbCollection GetWebPartVerbs(WebPart webPart)
    {
      ArrayList verbSet = new ArrayList();
      foreach (WebPartVerb verb in base.GetWebPartVerbs(webPart))
      {
        if (verb.Text != "Close")
          verbSet.Add(verb);
      }
      WebPartVerbCollection reducedVerbSet = 
        new WebPartVerbCollection(verbSet);
      return reducedVerbSet;
    }

    protected override Style CreateWebPartChromeStyle(WebPart part, 
      PartChromeType chromeType)
    {
      Style finalStyle = new Style();
      finalStyle.CopyFrom(base.CreateWebPartChromeStyle(part, chromeType));
      finalStyle.Font.Name = "Verdana";
      return finalStyle;
    }

    protected override void RenderPartContents(HtmlTextWriter writer, 
      WebPart part)
    {

        if (part == this.WebPartManager.SelectedWebPart)
          HttpContext.Current.Response.Write("<span>Not rendered</span>");
        else
          if(this.Zone.GetType() == typeof(MyZone))
            part.RenderControl(writer);
    }
  }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class MyZone
    Inherits WebPartZone
    Private _renderVerbsInMenu As Boolean

    Protected Overrides Function CreateWebPartChrome() As WebPartChrome
      Dim theChrome As WebPartChrome = _
        New MyWebPartChrome(Me, Me.WebPartManager)
      If RenderVerbsInMenu Then
        Me.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
      Else
        Me.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar
      End If
      Return theChrome
    End Function

    Public Property RenderVerbsInMenu() As Boolean
      Get
        Return _renderVerbsInMenu
      End Get
      Set(ByVal value As Boolean)
        _renderVerbsInMenu = value
      End Set
    End Property

  End Class

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class MyWebPartChrome
    Inherits WebPartChrome
    Dim theManager As WebPartManager
    Dim theZone As WebPartZoneBase

    Public Sub New(ByVal aZone As WebPartZoneBase, _
      ByVal aManager As WebPartManager)

      MyBase.New(aZone, aManager)
      theManager = aManager
      theZone = aZone
    End Sub

    Protected Overrides Function GetWebPartVerbs _
      (ByVal webPart As WebPart) As WebPartVerbCollection

      Dim verbSet As New ArrayList()
      Dim verb As WebPartVerb
      For Each verb In MyBase.GetWebPartVerbs(webPart)
        If verb.Text <> "Close" Then
          verbSet.Add(verb)
        End If
      Next verb

      Dim reducedVerbSet As WebPartVerbCollection = _
        New WebPartVerbCollection(verbSet)

      Return reducedVerbSet
    End Function

    Protected Overrides Function CreateWebPartChromeStyle _
      (ByVal part As WebPart, ByVal chromeType As PartChromeType) As Style

      Dim finalStyle As New Style()
      finalStyle.CopyFrom(MyBase.CreateWebPartChromeStyle(Part, chromeType))
      finalStyle.Font.Name = "Verdana"
      Return finalStyle
    End Function

    Protected Overrides Sub RenderPartContents _
      (ByVal writer As HtmlTextWriter, ByVal part As WebPart)

      If part Is Me.WebPartManager.SelectedWebPart Then
        HttpContext.Current.Response.Write("<span>Not rendered</span>")
      Else
        If (Me.Zone.GetType() Is GetType(MyZone)) Then
          part.RenderControl(writer)
        End If
      End If

    End Sub

  End Class

End Namespace

설명

WebPartChrome 클래스의 새 인스턴스를 초기화합니다 WebPartChrome . 주로 WebPartZoneBase 메서드의 영역에서 크롬 렌더링 및 영역 CreateWebPartChrome 의 컨트롤에 대한 WebPart 사용자 지정 렌더링을 처리하는 개체의 WebPartChrome 인스턴스를 만드는 데 사용됩니다.

적용 대상

추가 정보