Compartilhar via


ToolPane Class

Represents the tool pane on a Web Part Page. This class cannot be inherited.

Inheritance Hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.CompositeControl
        System.Web.UI.WebControls.WebParts.WebZone
          System.Web.UI.WebControls.WebParts.ToolZone
            System.Web.UI.WebControls.WebParts.EditorZoneBase
              Microsoft.SharePoint.WebPartPages.ToolPane

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class ToolPane _
    Inherits EditorZoneBase _
    Implements INamingContainer
'Usage
Dim instance As ToolPane
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ToolPane : EditorZoneBase, 
    INamingContainer

Examples

The following example demonstrates the use of the ToolPane class and the three methods of the ICustomizeToolPane interface in a simple Web Part. The RenderWebPart method uses the GetShowExtensibleToolPaneEvent to associate a button control on the Web Part with the JavaScript required to open the extensible tool pane. The ToolPaneTemplate property provides the layout of the tool pane, while the CreateToolPaneControls method draws the tool pane's controls.

'The custom WebPart class
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages

<ToolboxData("<{0}:WPToolPaneTest runat=server></{0}:WPToolPaneTest>"), _
XmlRoot(Namespace:="WPToolPaneTest")> _
 Public Class WPToolPaneTest
    Inherits Microsoft.SharePoint.WebPartPages.WebPart
    Implements ICustomizeToolPane

    Public Sub New()
    End Sub

    Protected Overrides Sub RenderWebPart(ByVal output As 
    System.Web.UI.HtmlTextWriter)
        output.Write("Web Part with an extensible tool pane.<br><br>")
        output.Write("<input type=""button"" class=""ms-SPButton"" 
            value=""Show Extensible ToolPane"" ")
        output.Write("onclick=""" & ToolPane.
            GetShowExtensibleToolPaneEvent("'" & Me.UniqueID & "'"))
        output.Write("""/><br><br>")
    End Sub

    Public Sub CreateToolPaneControls(ByVal toolpane As 
    Microsoft.SharePoint.WebPartPages.ToolPane) _
    Implements Microsoft.SharePoint.WebPartPages.ICustomizeToolPane.
        CreateToolPaneControls
        ' Display a custom tool part followed by the standard properties
        Dim myToolPart As TPToolPaneTest = New TPToolPaneTest
        toolpane.InsertToolPart(0, myToolPart)
        Dim standardToolPart As WebPartToolPart = New WebPartToolPart
        toolpane.InsertToolPart(1, standardToolPart)
    End Sub

    Public Function ShowZoneIdentification() As Boolean _
    Implements Microsoft.SharePoint.WebPartPages.ICustomizeToolPane.
            ShowZoneIdentification
        Return True
    End Function

    Public ReadOnly Property ToolPaneTemplate() As String _
    Implements Microsoft.SharePoint.WebPartPages.ICustomizeToolPane.
            ToolPaneTemplate
        Get
            Dim myTemplate As String
            myTemplate = "<?xml version=""1.0""?>"
            myTemplate &= "<ToolPane>"
            myTemplate &= "<Caption title=""Test Toolpane"" 
                name=""Test Toolpane""></Caption>"
            myTemplate &= "<ToolBar></ToolBar>"
            myTemplate &= "<ErrorUI></ErrorUI>"
            myTemplate &= "<FixedArea></FixedArea>"
            myTemplate &= "<NotifyUI></NotifyUI>"
            myTemplate &= "<ToolParts></ToolParts>"
            myTemplate &= "<Commands ok=""true"" cancel=""true"" 
                apply=""true""></Commands>"
            myTemplate &= "</ToolPane>"
            Console.WriteLine(myTemplate)
            Return myTemplate
        End Get
    End Property
End Class
'The custom ToolPart class
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebPartPages

Public Class TPToolPaneTest
    Inherits Microsoft.SharePoint.WebPartPages.ToolPart

    Sub New()
    End Sub

    Protected Overrides Sub RenderToolPart(ByVal output As 
    System.Web.UI.HtmlTextWriter)
        output.RenderBeginTag(HtmlTextWriterTag.Div)
        output.Write("Properties are displayed here for editing.")
        output.RenderEndTag()
    End Sub

    Private Sub TPToolPaneTest_Init(ByVal sender As Object, ByVal e As 
    System.EventArgs) Handles MyBase.Init
        Me.Title = "TPToolPaneTest"
    End Sub

End Class
//The custom WebPart class
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;

[ToolboxData("<{0}:WPToolPaneTest runat=server></{0}:WPToolPaneTest>"), 
    XmlRoot(Namespace="WPToolPaneTest")]
 public class WPToolPaneTest:
    Microsoft.SharePoint.WebPartPages.WebPart,
    ICustomizeToolPane

 {
    public WPToolPaneTest()
    {
    }

    protected override void RenderWebPart(System.Web.UI.HtmlTextWriter output)
    {
        output.Write("Web Part with an extensible tool pane.<br><br>");
        output.Write("<input type=\"button\" class=\"ms-SPButton\" 
            value=\"Show Extensible ToolPane\" ");
        output.Write("onclick=\""+ToolPane.
            GetShowExtensibleToolPaneEvent("'"+this.UniqueID+"'"));
        output.Write("\"/><br><br>");
    }

    public void CreateToolPaneControls(Microsoft.SharePoint.
        WebPartPages.ToolPane toolpane)
    {
        // Display a custom tool part followed by the standard properties
        TPToolPaneTest myToolPart = new TPToolPaneTest;
        toolpane.InsertToolPart(0, myToolPart);
        WebPartToolPart standardToolPart = new WebPartToolPart;
        toolpane.InsertToolPart(1, standardToolPart);
    }

    public bool ShowZoneIdentification()
    {
        return true;
    }

    public string ToolPaneTemplate    
    {
        get
        {
            string myTemplate;
            myTemplate = "<?xml version=\"1.0\"?>";
            myTemplate &= "<ToolPane>";
            myTemplate &= "<Caption title=\"Test Toolpane\" 
                name=\"Test Toolpane\"></Caption>";
            myTemplate &= "<ToolBar></ToolBar>";
            myTemplate &= "<ErrorUI></ErrorUI>";
            myTemplate &= "<FixedArea></FixedArea>";
            myTemplate &= "<NotifyUI></NotifyUI>";
            myTemplate &= "<ToolParts></ToolParts>";
            myTemplate &= "<Commands ok=\"true\" cancel=\"true\" 
                apply=\"true\"></Commands>";
            myTemplate &= "</ToolPane>";
            Console.WriteLine(myTemplate);
            return myTemplate;
        }
    }
 }//The custom ToolPart class
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;



public class TPToolPaneTest:
    Microsoft.SharePoint.WebPartPages.ToolPart
{
    TPToolPaneTest()
    {
        this.Init += new EventHandler(TPToolPaneTest_Init);
    }

    protected overrides void 
        RenderToolPart(System.Web.UI.HtmlTextWriter output)
    {
        output.RenderBeginTag(HtmlTextWriterTag.Div);
        output.Write("Properties are displayed here for editing.");
        output.RenderEndTag();
    }

    private void TPToolPaneTest_Init(object sender, System.EventArgs e)
    {
        this.Title = "TPToolPaneTest";
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

ToolPane Members

Microsoft.SharePoint.WebPartPages Namespace