Share via


ToolWindow Class

When overridden by a derived class, represents a tool window in the generated designer for a domain-specific language.

This API is not CLS-compliant. 

Namespace:  Microsoft.VisualStudio.Modeling.Shell
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Shell (in Microsoft.VisualStudio.Modeling.Sdk.Shell.dll)

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public MustInherit Class ToolWindow _
    Inherits ModelingWindowPane
'Usage
Dim instance As ToolWindow
[CLSCompliantAttribute(false)]
public abstract class ToolWindow : ModelingWindowPane
[CLSCompliantAttribute(false)]
public ref class ToolWindow abstract : public ModelingWindowPane
public abstract class ToolWindow extends ModelingWindowPane

Remarks

Before you can add a tool window to the generated designer, you must register the window. For more information, see [Microsoft.VisualStudio.Modeling.Shell.ModelingPackage].

Examples

The following example adds a tool window called Custom Tool Window to a domain-specific language project that is named RegisterTools. When you open your project in the generated designer, the tab for this window appears next to Solution Explorer. When you click this tab, a label that reads This is the custom tool window appears in the middle of the tool window.

This code registers the tool window:

using VSShellInterop = Microsoft.VisualStudio.Shell.Interop;
using VSShell = Microsoft.VisualStudio.Shell;
using DslShell = Microsoft.VisualStudio.Modeling.Shell;
using DslDesign = Microsoft.VisualStudio.Modeling.Design;
using VSTextTemplatingHost = Microsoft.VisualStudio.TextTemplating.VSHost;

namespace MS.RegisterTools.DslPackage
{
    [VSShell::ProvideToolWindowVisibility(typeof(CustomToolWindow), 
              Constants.RegisterToolsEditorFactoryId)]
    [VSShell::ProvideToolWindow(typeof(CustomToolWindow), 
              MultiInstances = false, 
              Style = VSShell::VsDockStyle.Tabbed, 
              Orientation = VSShell::ToolWindowOrientation.Right, 
              Window = "{3AE79031-E1BC-11D0-8F78-00A0C9110057}")]

    internal partial class RegisterToolsPackage
    {
        //Initializes the base class for the package
        protected override void Initialize()
        {
            base.Initialize();

            //Registers the custom tool window
            this.AddToolWindow(typeof(CustomToolWindow));
        }
    }
}

This code defines the tool window:

using System;
using System.Windows.Forms;
using VSShellInterop = Microsoft.VisualStudio.Shell.Interop;
using VSShell = Microsoft.VisualStudio.Shell;
using DslShell = Microsoft.VisualStudio.Modeling.Shell;
using DslDesign = Microsoft.VisualStudio.Modeling.Design;
using VSTextTemplatingHost = Microsoft.VisualStudio.TextTemplating.VSHost;

namespace MS.RegisterTools.DslPackage
{

    //Creates a tool window and gives it a title, icon, and label
    internal class CustomToolWindow : DslShell.ToolWindow
    {

        //defines a label
  private Label myLabel;
        
        //creates the tool window
  public CustomToolWindow(IServiceProvider serviceProvider) : base(serviceProvider)
  { 
  }

        //gets the icon for the tool window
        protected override int BitmapResource
        {
            get { return 104; }
        }

        //gets the index for the icon
        protected override int BitmapIndex
        {
            get { return 0; }
        }

        //gets the name of the tool window
        public override string WindowTitle
        {
            get { return "Custom Window"; }
        }

        //sets up a label
  protected override void OnToolWindowCreate()
  {
      this.myLabel = new Label();
this.myLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.myLabel.Text = "This is the custom tool window";
   }

        //puts a label on the tool window
  public override System.Windows.Forms.IWin32Window Window
  {
       get { return this.myLabel; }
  }
    }
}

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Shell.WindowPane
    Microsoft.VisualStudio.Modeling.Shell.ModelingWindowPane
      Microsoft.VisualStudio.Modeling.Shell.ToolWindow
        Microsoft.VisualStudio.Modeling.Shell.ModelExplorerToolWindow

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

ToolWindow Members

Microsoft.VisualStudio.Modeling.Shell Namespace