EditorPart クラスとは? わかりやすく解説

EditorPart クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

EditorZoneBase ゾーンにあるコントロール基本クラスとして機能しWebPart コントロール編集使用されます。

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

<BindableAttribute(False)> _
Public MustInherit Class
 EditorPart
    Inherits Part
[BindableAttribute(false)] 
public abstract class EditorPart : Part
[BindableAttribute(false)] 
public ref class EditorPart abstract : public
 Part
/** @attribute BindableAttribute(false) */ 
public abstract class EditorPart extends Part
BindableAttribute(false) 
public abstract class EditorPart extends
 Part
解説解説

EditorPart クラスは、Web パーツ コントロール セット提供される派生 EditorPart コントロール、およびカスタム EditorPart コントロールによって使用されるプロパティおよびメソッド基本セット提供しますEditorPart コントロールでは、ユーザーが、関連付けられている WebPart コントロールを、そのレイアウト外観プロパティ動作、またはその他の特性変更することによって編集できます

編集するユーザー インターフェイス (UI) は、EditorPart コントロールを含む EditorZoneBase ゾーン構成されており、Web ページ編集モードになると表示されます。

メモメモ

EditorPart コントロールは、EditorZone コントロールなどの EditorZoneBase クラスから派生したゾーン内でのみ使用できます

ページ編集モードになった後、ユーザーWebPart コントロール選択し、そのコントロール動詞メニューedit 動詞クリックすることによって編集できます編集できる WebPart コントロール一度1 つだけです。

Web パーツ コントロール セットでは、次の表に示すように複数派生 EditorPart コントロール提供されます。これらのコントロールは、ほとんどのアプリケーション必要なすべての編集機能提供しますWeb パーツ ページでこれらのコントロール使用する通常の方法は、それらを <zonetemplate> 要素ページ永続形式宣言する方法です。ここでは、<zonetemplate><asp:editorzone> 要素の子要素です。コード例については、このトピックの「使用例」を参照してください

コントロール種類

説明

AppearanceEditorPart

タイトル テキスト、高さ、幅、および境界線の各属性などのプロパティなど、関連付けられているコントロール外観編集します

BehaviorEditorPart

関連付けられているコントロールについて、それを編集できるかどうか終了できるかどうか、または別のゾーン移動できるかどうかなど、特定の動作編集します。このコントロールは、共有パーソナル化スコープコントロール編集中の場合にだけページ表示されます。

LayoutEditorPart

関連付けられているコントロールについて、それが標準の状態であるか最小化 (折りたたまれた) 状態であるか、または配置されているゾーンはどれかなどのレイアウト属性編集します

PropertyGridEditorPart

関連付けられているコントロールプロパティソース コードWebBrowsable 属性宣言されていた場合に、それらのプロパティ編集します

継承時の注意 カスタム EditorPart コントロール作成するには、2 つ重要なメソッドオーバーライドする必要があります。ApplyChanges メソッドは、エディタ コントロール行われた変更を、編集中の WebPart コントロール適用します。SyncChanges メソッドは、エディタ コントロール編集できるように、編集中の WebPart コントロール現在の値を取得します。これらの 2 つ重要なメソッド使用してカスタム EditorPart コントロール編集中の WebPart コントロールの間で値を取得および設定しますEditorPart クラスから派生させてカスタムエディタ コントロール作成する場合は、WebPart コントロールユーザー コントロール、またはサーバー コントロールに IWebEditable インターフェイス実装することによって、各自カスタム コントロールEditorZoneBase ゾーン追加できます詳細およびコード例については、IWebEditable クラス概要参照してくださいまた、カスタム WebPart コントロールIWebEditable実装する方法を「使用例」のコード例示します

使用例使用例

EditorPart コントロールを、宣言使用する方法およびプログラム使用する方法を示すコード例次に示します。このコード例は、4 つ部分構成されます。

コード例最初部分は、Web ページ上の表示モードユーザー変更できるようにするユーザー コントロールです。表示モード詳細、およびこのコントロールソース コード説明については、「チュートリアル : Web パーツ ページでの表示モード変更」を参照してください

<%@ control language="vb" classname="DisplayModeMenuVB"%>

<script runat="server">
  
' Use a field to reference the current WebPartManager.
Dim _manager As WebPartManager


Sub Page_Init(ByVal sender As
 Object, ByVal e As EventArgs)
 
    AddHandler Page.InitComplete, AddressOf
 InitComplete

End Sub 


Sub InitComplete(ByVal sender As
 Object, ByVal e As System.EventArgs)
 
    _manager = WebPartManager.GetCurrentWebPartManager(Page)
    
    Dim browseModeName As String
 = WebPartManager.BrowseDisplayMode.Name
    
    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In  _manager.SupportedDisplayModes
        Dim modeName As String
 = mode.Name
        ' Make sure a mode is enabled before adding it.
        If mode.IsEnabled(_manager) Then
            Dim item As New
 ListItem(modeName + " Mode", modeName)
            DisplayModeDropdown.Items.Add(item)
        End If
    Next mode

End Sub 
 

' Change the page to the selected display mode.
Sub DisplayModeDropdown_SelectedIndexChanged(ByVal
 sender As Object, ByVal
 e As EventArgs) 
    Dim selectedMode As String
 = DisplayModeDropdown.SelectedValue
    
    Dim mode As WebPartDisplayMode = _manager.SupportedDisplayModes(selectedMode)
    If Not (mode Is Nothing)
 Then
        _manager.DisplayMode = mode
    End If
 
End Sub 


Sub Page_PreRender(ByVal sender As
 Object, ByVal e As EventArgs)
 
    DisplayModeDropdown.SelectedValue = _manager.DisplayMode.Name

End Sub 

</script>
<div>
  <asp:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged"
 />
</div>
<%@ control language="C#" classname="DisplayModeMenuCS"%>

<script runat="server">
  
 // Use a field to reference the current WebPartManager.
  WebPartManager _manager;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }  

  void InitComplete(object sender, System.EventArgs e)
  {
    _manager = WebPartManager.GetCurrentWebPartManager(Page);

    String browseModeName = WebPartManager.BrowseDisplayMode.Name;

    // Fill the dropdown with the names of supported display modes.
    foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
    {
      String modeName = mode.Name;
      // Make sure a mode is enabled before adding it.
      if (mode.IsEnabled(_manager))
      {
        ListItem item = new ListItem(modeName + " Mode",
 modeName);
        DisplayModeDropdown.Items.Add(item);
      }
    }

  }
 
  // Change the page to the selected display mode.
  void DisplayModeDropdown_SelectedIndexChanged(object sender,
 
    EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;

    WebPartDisplayMode mode = _manager.SupportedDisplayModes[selectedMode];
    if (mode != null)
      _manager.DisplayMode = mode;

  }

  void Page_PreRender(object sender, EventArgs e)
  {
    DisplayModeDropdown.SelectedValue = _manager.DisplayMode.Name;
  }
  
</script>
<div>
  <asp:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
</div>

コード例2 番目の部分Web ページです。ここには、EditorZone コントロールへの宣言参照、および子の <zonetemplate> 要素含まれます。この子要素には Web パーツ コントロール セット2 つEditorPart コントロールへの宣言参照含まれています。ページは、アセンブリRegister ディレクティブ使用してカスタム WebPart コントロール参照、およびコントロール<aspSample:TextDisplayWebPart> 要素参照行います

<%@ page language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModevb.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls"
 
  Assembly="TextDisplayWebPartVB"
 %>

<html>
  <head id="Head1" runat="server">
    <title>
      Text Display WebPart with EditorPart
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1"
 runat="server" />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1"
 runat="server" />
      <asp:webpartzone id="zone1" runat="server"
 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" /> 
         
        </zonetemplate>
      </asp:webpartzone> 
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1"
 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1"
 
            runat="server" />
        </ZoneTemplate>      
      </asp:EditorZone>
    </form>
  </body>
</html>
<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModecs.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="TextDisplayWebPartCS" %>

<html>
  <head runat="server">
    <title>
      Text Display WebPart with EditorPart
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server"
 />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1" runat="server"
 />
      <asp:webpartzone id="zone1" runat="server" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />          
        </zonetemplate>
      </asp:webpartzone> 
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1" 
            runat="server" />
        </ZoneTemplate>      
      </asp:EditorZone>
    </form>
  </body>
</html>

コード例3 番目の部分は、TextDisplayWebPart という名前のカスタム WebPart クラスです。このクラスは、IWebEditable インターフェイス実装ます。このクラス内で入れ子になっているのは、TextDisplayWebPart クラス関連付けられている、TextDisplayEditorPart という名前のプライベートEditorPart クラスコードを含むプライベート クラスです。実行時に、TextDisplayWebPart コントロール編集モードになり、その TextDisplayWebPart.CreateEditorParts メソッドTextDisplayEditorPart クラスインスタンス作成し、それを EditorZone コントロール内で他の EditorPart コントロールと共に表示します

Imports System
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 TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String
 = Nothing
    Private _fontStyle As String
 = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    Private lineBreak As Literal

    Public Overrides Function
 CreateEditorParts() _
                                As EditorPartCollection
      Dim editorArray As New
 ArrayList()
      Dim edPart as New
 TextDisplayEditorPart()
      edPart.ID = Me.ID & "_editorPart1"
      editorArray.Add(edPart)
      Dim editorParts As New
 EditorPartCollection(editorArray)
      Return editorParts

    End Function

    Public Overrides ReadOnly
 Property WebBrowsableObject() _
                                        As Object
      Get
        Return Me
      End Get
    End Property

    <Personalizable(), WebBrowsable()> _
    Public Property ContentText() As
 String
      Get
        Return _contentText
      End Get
      Set(ByVal value As
 String)
        _contentText = Value
      End Set
    End Property

    <Personalizable(), WebBrowsable()> _
    Public Property FontStyle() As
 String
      Get
        Return _fontStyle
      End Get
      Set(ByVal value As
 String)
        _fontStyle = Value
      End Set
    End Property

    Protected Overrides Sub
 CreateChildControls()
      Controls.Clear()
      DisplayContent = New Label()
      DisplayContent.BackColor = Color.LightBlue
      DisplayContent.Text = Me.ContentText
      If FontStyle Is Nothing
 Then
        FontStyle = "None"
      End If
      SetFontStyle(DisplayContent, FontStyle)
      Me.Controls.Add(DisplayContent)

      lineBreak = New Literal()
      lineBreak.Text = "<br />"
      Controls.Add(lineBreak)

      input = New TextBox()
      Me.Controls.Add(input)
      Dim update As New
 Button()
      update.Text = "Set Label Content"
      AddHandler update.Click, AddressOf Me.submit_Click
      Me.Controls.Add(update)

    End Sub

    Private Sub submit_Click(ByVal
 sender As Object, _
                             ByVal e As EventArgs)
      ' Update the label string.
      If input.Text <> String.Empty Then
        _contentText = input.Text + "<br />"
        input.Text = String.Empty
        DisplayContent.Text = Me.ContentText
      End If

    End Sub

    Private Sub SetFontStyle(ByVal
 label As Label, _
                             ByVal selectedStyle As
 String)
      If selectedStyle = "Bold"
 Then
        label.Font.Bold = True
        label.Font.Italic = False
        label.Font.Underline = False
      ElseIf selectedStyle = "Italic"
 Then
        label.Font.Italic = True
        label.Font.Bold = False
        label.Font.Underline = False
      ElseIf selectedStyle = "Underline"
 Then
        label.Font.Underline = True
        label.Font.Bold = False
        label.Font.Italic = False
      Else
        label.Font.Bold = False
        label.Font.Italic = False
        label.Font.Underline = False
      End If

    End Sub

    ' Create a custom EditorPart to edit the WebPart control.
    <AspNetHostingPermission(SecurityAction.Demand, _
      Level:=AspNetHostingPermissionLevel.Minimal)> _
    Private Class TextDisplayEditorPart
      Inherits EditorPart
      Private _partContentFontStyle As DropDownList

      Public Sub New()
        Title = "Font Face"
      End Sub

      Public Overrides Function
 ApplyChanges() As Boolean
        Dim part As TextDisplayWebPart = CType(WebPartToEdit,
 _
                                               TextDisplayWebPart)
        ' Update the custom WebPart control with the font style.
        part.FontStyle = PartContentFontStyle.SelectedValue

        Return True

      End Function

      Public Overrides Sub
 SyncChanges()
        Dim part As TextDisplayWebPart = CType(WebPartToEdit,
 _
                                               TextDisplayWebPart)
        Dim currentStyle As String
 = part.FontStyle

        ' Select the current font style in the drop-down control.
        Dim item As ListItem
        For Each item In
 PartContentFontStyle.Items
          If item.Value = currentStyle Then
            item.Selected = True
            Exit For
          End If
        Next item

      End Sub

      Protected Overrides Sub
 CreateChildControls()
        Controls.Clear()

        ' Add a set of font styles to the dropdown list.
        _partContentFontStyle = New DropDownList()
        _partContentFontStyle.Items.Add("Bold")
        _partContentFontStyle.Items.Add("Italic")
        _partContentFontStyle.Items.Add("Underline")
        _partContentFontStyle.Items.Add("None")

        Controls.Add(_partContentFontStyle)

      End Sub

      Protected Overrides Sub
 RenderContents(ByVal writer _
                                             As HtmlTextWriter)
        writer.Write("<b>Text Content Font Style</b>")
        writer.WriteBreak()
        writer.Write("Select a font style.")
        writer.WriteBreak()
        _partContentFontStyle.RenderControl(writer)
        writer.WriteBreak()

      End Sub

      ' Access the drop-down control through a property.
      Private ReadOnly Property
 PartContentFontStyle() As DropDownList
        Get
          EnsureChildControls()
          Return _partContentFontStyle
        End Get
      End Property

    End Class

  End Class

End Namespace
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 TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    private String _fontStyle = null;
    TextBox input;
    Label DisplayContent;
    Literal lineBreak;

    public override EditorPartCollection CreateEditorParts()
    {
      ArrayList editorArray = new ArrayList();
      TextDisplayEditorPart edPart = new TextDisplayEditorPart();
      edPart.ID = this.ID + "_editorPart1";
      editorArray.Add(edPart);
      EditorPartCollection editorParts = 
        new EditorPartCollection(editorArray);
      return editorParts;
    }

    public override object WebBrowsableObject
    {
      get { return this;
 }
    }

    [Personalizable(), WebBrowsable]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    [Personalizable(), WebBrowsable()]
    public String FontStyle
    {
      get { return _fontStyle; }
      set { _fontStyle = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      if (FontStyle == null)
        FontStyle = "None";
      SetFontStyle(DisplayContent, FontStyle);
      this.Controls.Add(DisplayContent);

      lineBreak = new Literal();
      lineBreak.Text = @"<br />";
      Controls.Add(lineBreak);

      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);

    }

    private void submit_Click(object sender,
 EventArgs e)
    {
      // Update the label string.
      if (input.Text != String.Empty)
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }

    private void SetFontStyle(Label label,
 String selectedStyle)
    {
      if (selectedStyle == "Bold")
      {
        label.Font.Bold = true;
        label.Font.Italic = false;
        label.Font.Underline = false;
      }
      else if (selectedStyle == "Italic")
      {
        label.Font.Italic = true;
        label.Font.Bold = false;
        label.Font.Underline = false;
      }
      else if (selectedStyle == "Underline")
      {
        label.Font.Underline = true;
        label.Font.Bold = false;
        label.Font.Italic = false;
      }
      else
      {
        label.Font.Bold = false;
        label.Font.Italic = false;
        label.Font.Underline = false;
      }
    }

    // Create a custom EditorPart to edit the WebPart control.
    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    private class TextDisplayEditorPart : EditorPart
    {
      DropDownList _partContentFontStyle;

      public TextDisplayEditorPart()
      {
        Title = "Font Face";
      }

      public override bool ApplyChanges()
      {
        TextDisplayWebPart part = 
          (TextDisplayWebPart)WebPartToEdit;
        // Update the custom WebPart control with the font style.
        part.FontStyle = PartContentFontStyle.SelectedValue;

        return true;
      }

      public override void SyncChanges()
      {
        TextDisplayWebPart part = 
          (TextDisplayWebPart)WebPartToEdit;
        String currentStyle = part.FontStyle;

        // Select the current font style in the drop-down control.
        foreach (ListItem item in PartContentFontStyle.Items)
        {
          if (item.Value == currentStyle)
          {
            item.Selected = true;
            break;
          }
        }
      }


      protected override void CreateChildControls()
      {
        Controls.Clear();

        // Add a set of font styles to the dropdown list.
        _partContentFontStyle = new DropDownList();
        _partContentFontStyle.Items.Add("Bold");
        _partContentFontStyle.Items.Add("Italic");
        _partContentFontStyle.Items.Add("Underline");
        _partContentFontStyle.Items.Add("None");

        Controls.Add(_partContentFontStyle);

      }

      protected override void RenderContents(HtmlTextWriter
 writer)
      {
        writer.Write("<b>Text Content Font Style</b>");
        writer.WriteBreak();
        writer.Write("Select a font style.");
        writer.WriteBreak();
        _partContentFontStyle.RenderControl(writer);
        writer.WriteBreak();
      }

      // Access the drop-down control through a property.
      private DropDownList PartContentFontStyle
      {
        get 
        {
          EnsureChildControls();
          return _partContentFontStyle;
        }
      }
    }
  }
}

ブラウザページ読み込み、[Display Mode] コントロールの [編集モード] を選択して編集モード切り替えますTextDisplayWebPart コントロールタイトル バー動詞メニュー (下向き矢印) をクリックし、[編集] をクリックしてコントロール編集します編集中の UI表示状態の場合TextDisplayWebPart.FontStyle プロパティ編集できるカスタム コントロールを含む 3 つの EditorPart コントロール表示されます。編集中の UI変更行い、[適用] ボタンクリックした場合ドロップダウン リスト コントロール使用してページブラウズ モード戻し編集中の変更をすべて反映した結果表示できます

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.Panel
         System.Web.UI.WebControls.WebParts.Part
          System.Web.UI.WebControls.WebParts.EditorPart
             System.Web.UI.WebControls.WebParts.AppearanceEditorPart
             System.Web.UI.WebControls.WebParts.BehaviorEditorPart
             System.Web.UI.WebControls.WebParts.LayoutEditorPart
             System.Web.UI.WebControls.WebParts.PropertyGridEditorPart
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EditorPart メンバ
System.Web.UI.WebControls.WebParts 名前空間
EditorZoneBase
EditorZone
IWebEditable
その他の技術情報
Web パーツパーソナル化概要
ASP.NET Web パーツ ページ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「EditorPart クラス」の関連用語

EditorPart クラスのお隣キーワード
検索ランキング

   

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



EditorPart クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS