简体   繁体   English

如何以编程方式将Visual Studio加载项窗口附加到选项卡?

[英]How do I attach my Visual Studio Add-in window to a tab programmatically?

I'm creating a small addin in the hopes of making it fun and easy to play with graphics in Visual Studio. 我正在创建一个小型插件,以期使它在Visual Studio中变得有趣且易于使用。 There has been one small annoyance though, I can't seem to figure out how to attach my newly created window to the tab bar. 尽管有一个小麻烦,但我似乎无法弄清楚如何将我新创建的窗口附加到选项卡栏。

It's all F#, but the solution should be just a couple of function calls so please feel free to use C# or VB in your answer. 全部都是F#,但是解决方案应该只是几个函数调用,因此请随时在答案中使用C#或VB。

type WindowManager(applicationObject: DTE2, addInInstance: AddIn) = 
    member this.CreateWindow(control: Type, caption) = 
        let windowInterface = applicationObject.Windows :?> Windows2
        let tempObj = ref null
        let assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location
        let className = control.FullName
        let instanceGuid = System.Guid.NewGuid().ToString("B")
        let toolWindow = windowInterface.CreateToolWindow2( addInInstance, assemblyLocation, className, caption, instanceGuid, tempObj)
        toolWindow.Visible <- true

I think I just need to link it to something in the applicationObject. 我想我只需要将其链接到applicationObject中的某些内容即可。 The only problem is what. 唯一的问题是什么。

My understanding is that the only way to control tool window position is to provide it via a VSPackage, not via AddIn (see http://msdn.microsoft.com/en-us/library/bb166406.aspx and http://msdn.microsoft.com/en-us/library/bb165452.aspx for more information). 我的理解是,控制工具窗口位置的唯一方法是通过VSPackage而不是通过AddIn提供它(请参见http://msdn.microsoft.com/zh-cn/library/bb166406.aspxhttp:// msdn有关更多信息,请访问.microsoft.com / en-us / library / bb165452.aspx

I believe that the reason for this limitation is that positions of particular tool windows are user-controllable; 我相信这种限制的原因是特定工具窗口的位置是用户可控制的。 even if you provide the tool window via VSPackage and specify its position via the registry magic as described in the above links, you still only control the location of a first appearance of a tool window. 即使您通过VSPackage提供了工具窗口并通过注册表魔术符如上面的链接中所述指定了它的位置,您仍然仍然只能控制工具窗口首次出现的位置。 After that, the location will always come from wherever the user moved your toolwindow, and this is very deliberately non-overridable. 之后,该位置将始终来自用户移动您的工具窗口的任何位置,这是有意不可覆盖的。

I might be missing some new VS2010 mechanisms though. 我可能会缺少一些新的VS2010机制。

I seem to have figured it out: 我似乎已经知道了:

toolWindow.Linkable <- false
toolWindow.WindowState <- vsWindowState.vsWindowStateMaximize
toolWindow.Visible <- true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM