ToolWindow 类

当通过派生类重写时,为域特定语言在生成的设计器中表示工具窗口。

此 API 不兼容 CLS。 

继承层次结构

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

命名空间:  Microsoft.VisualStudio.Modeling.Shell
程序集:  Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.Shell.12.0.dll 中)

语法

声明
<CLSCompliantAttribute(False)> _
Public MustInherit Class ToolWindow _
    Inherits ModelingWindowPane
[CLSCompliantAttribute(false)]
public abstract class ToolWindow : ModelingWindowPane

ToolWindow 类型公开以下成员。

构造函数

  名称 说明
受保护的方法 ToolWindow 初始化 ToolWindow 类的新实例。

页首

属性

  名称 说明
公共属性 ActiveInPlaceEditWindow 获取并设置就地编辑的激活窗口。 (继承自 ModelingWindowPane。)
受保护的属性 BitmapIndex 当在派生类中重写时,获取出现在工具窗口名称旁边的位图索引。
受保护的属性 BitmapResource 当在派生类中重写时,获取出现在工具窗口名称旁边的位图的资源 ID。
公共属性 Content (继承自 WindowPane。)
公共属性 DocData 获取内存中的文档。
受保护的属性 EnableUndo 获取工具窗口和启用“取消”命令。
公共属性 Frame 获取与此窗口相对应的 IVsWindowFrame。 (继承自 ModelingWindowPane。)
受保护的属性 HasSelectableObjects 如果文件不加载,获取工具窗口功能失败”选择对象“命令。 (重写 ModelingWindowPane.HasSelectableObjects。)
受保护的属性 HasToolBar 获取工具窗口并验证是否应具有工具栏。
受保护的属性 HelpService 获取帮助服务。 (继承自 ModelingWindowPane。)
受保护的属性 InitializationMode (继承自 WindowPane。)
公共属性 MenuService 获取菜单命令服务。 (继承自 ModelingWindowPane。)
公共属性 PrimarySelection 获取窗口窗格中的主要选定元素。 (继承自 ModelingWindowPane。)
受保护的属性 SelectedElements 获取在窗口窗格中被选中的元素。 (继承自 ModelingWindowPane。)
公共属性 SelectionCount 获取窗口窗格中选定的元素数。 (继承自 ModelingWindowPane。)
受保护的属性 SelectionHelpService 获取选定内容帮助服务。 (继承自 ModelingWindowPane。)
受保护的属性 ServiceProvider 获取位于该窗口窗格的服务提供程序。 (继承自 ModelingWindowPane。)
受保护的属性 ToolBarHost 获取 IVsToolWindowToolbarHost 接口,定位工具栏如何在工具窗口中显示。
受保护的属性 ToolWindowFont 获取用于工具窗口的字体。
公共属性 Window (继承自 WindowPane。)
公共属性 WindowTitle 获取工具窗口的标题。

页首

方法

  名称 说明
受保护的方法 CommitPendingEditForCommand 在派生类中实现时,指定执行命令前是否应提交挂起的编辑。 (继承自 ModelingWindowPane。)
受保护的方法 CountAllObjects 获取窗口窗格中元素的数目。 (继承自 ModelingWindowPane。)
公共方法 CountObjects 窗口窗格或当前选定内容中元素数的计数。 (继承自 ModelingWindowPane。)
受保护的方法 CountSelectedObjects 获取当前内容中的文本元素的数目。 (继承自 ModelingWindowPane。)
公共方法 Dispose() (继承自 WindowPane。)
受保护的方法 Dispose(Boolean) 释放由 ToolWindow 占用的非托管资源,还可以另外再释放托管资源。 (重写 ModelingWindowPane.Dispose(Boolean)。)
受保护的方法 DoSelectObjects 在派生类中实现时,将在窗体窗格中选择元素。 (继承自 ModelingWindowPane。)
公共方法 Equals 确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
受保护的方法 GetAllObjects 获取窗口窗格中的所有元素。 (继承自 ModelingWindowPane。)
公共方法 GetComponentSelected 指定给定组件是否已选中。 (继承自 ModelingWindowPane。)
公共方法 GetContainerSelected 指定给定容器是否已选中。 (继承自 ModelingWindowPane。)
公共方法 GetHashCode 作为默认哈希函数。 (继承自 Object。)
公共方法 GetObjects 要么获取可以现在选择的元素,要么获取可以在窗玻璃中选择的元素。 (继承自 ModelingWindowPane。)
公共方法 GetSelectedComponents 获取窗口窗格中选中的组件。 (继承自 ModelingWindowPane。)
受保护的方法 GetSelectedObjects 获取在窗口窗格中被选中的元素。 (继承自 ModelingWindowPane。)
受保护的方法 GetService 获取指定类型的服务对象。重写此方法以返回自定义菜单命令服务。 (继承自 ModelingWindowPane。)
公共方法 GetSite 获取设置 SetSite的站点。 (继承自 ModelingWindowPane。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
公共方法 Hide 隐藏窗口窗格。 (继承自 ModelingWindowPane。)
受保护的方法 Initialize 初始化 ToolWindow 类的新实例。 (重写 WindowPane.Initialize()。)
公共方法 LoadUIState (继承自 WindowPane。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
受保护的方法 OnAfterToolWindowCreate 创建后初始化。
受保护的方法 OnClose 当窗口关闭时从快捷菜单选择移除窗口对象。 (继承自 ModelingWindowPane。)
受保护的方法 OnCreate 创建一个工具窗口。 (重写 WindowPane.OnCreate()。)
受保护的方法 OnDocumentWindowChanged 如果用户在文档窗口已做出更改,则通知派生类。
受保护的方法 OnSelectionChanged 在选择更改后通知事件侦听器。 (继承自 ModelingWindowPane。)
受保护的方法 OnSelectionChanging 在选择更改前通知事件侦听器。 (继承自 ModelingWindowPane。)
受保护的方法 OnToolWindowCreate 侦听在文档窗口的帧更改
受保护的方法 PreProcessMessage 处理窗口消息。 (继承自 ModelingWindowPane。)
公共方法 SaveUIState (继承自 WindowPane。)
公共方法 SelectObjects 选择窗口窗格中的元素。 (继承自 ModelingWindowPane。)
公共方法 SetSelectedComponents(ICollection) 添加指定的组件到选定容器,并通知选定更改的 shell。 (继承自 ModelingWindowPane。)
公共方法 SetSelectedComponents(ICollection, SelectionTypes) 目前尚未实现。 (继承自 ModelingWindowPane。)
公共方法 SetSite 在环境中初始化窗格。 (继承自 ModelingWindowPane。)
公共方法 Show 显示窗口窗格,使其成为显示在屏幕最前方的活动窗口。 (继承自 ModelingWindowPane。)
公共方法 ShowNoActivate 显示窗口窗格,使其成为显示在屏幕最前方的不可活动窗口。 (继承自 ModelingWindowPane。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

事件

  名称 说明
公共事件 SelectionChanged 在窗口窗格中的选择被更改之后激发。 (继承自 ModelingWindowPane。)
公共事件 SelectionChanging 在窗口窗格中的选择更改之前激发。 (继承自 ModelingWindowPane。)

页首

显式接口实现  

  名称 说明
显式接口实现私有方法 IVsWindowPane.ClosePane 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.CloseUIElementPane (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.CreatePaneWindow 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.CreateUIElementPane (继承自 WindowPane。)
显式接口实现私有方法 IOleCommandTarget.Exec (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.GetDefaultSize 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.GetDefaultUIElementSize (继承自 WindowPane。)
显式接口实现私有方法 IServiceProvider.GetService (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.LoadUIElementState (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.LoadViewState 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IOleCommandTarget.QueryStatus (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.SaveUIElementState (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.SaveViewState 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.SetSite 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.SetUIElementSite (继承自 WindowPane。)
显式接口实现私有方法 IVsWindowPane.TranslateAccelerator 已废弃不用。 (继承自 WindowPane。)
显式接口实现私有方法 IVsUIElementPane.TranslateUIElementAccelerator (继承自 WindowPane。)

页首

备注

在将工具窗口到位生成的设计器之前,必须先注册窗口。 有关详细信息,请参阅 ModelingPackage

示例

下面的示例将一个工具窗口调用 自定义工具窗口 到名为 RegisterTools 的特定于域的语言项目。 在中打开在编辑器中生成的设计器的项时,此窗口的选项卡 解决方案资源管理器旁边。 当您单击此选项时,读取 这是自定义工具窗口 的标签。工具窗口元显示。

此代码注册工具窗口:

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));
        }
    }
}

此代码定义工具窗口:

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; }
  }
    }
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参阅

参考

Microsoft.VisualStudio.Modeling.Shell 命名空间