如何以编程方式将 Visual Studio 外接程序窗口附加到选项卡?
我正在创建一个小插件,希望能够让 Visual Studio 中的图形处理变得有趣且轻松。不过,有一个小烦恼,我似乎不知道如何将新创建的窗口附加到选项卡栏。
全部都是 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
我想我只需要将它链接到 applicationObject 中的某些内容即可。唯一的问题是什么。
I'm creating a small addin in the hopes of making it fun and easy to play with graphics in 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.
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. The only problem is what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的理解是,控制工具窗口位置的唯一方法是通过 VSPackage 提供它,而不是通过 AddIn 提供(请参阅 http://msdn.microsoft.com/en-us/library/bb166406.aspx 和 http://msdn.microsoft.com/en-us/library/bb165452.aspx 了解更多信息)。
我认为这种限制的原因是特定工具窗口的位置是用户可控的;即使您通过 VSPackage 提供工具窗口并通过注册表魔术指定其位置(如上面链接所述),您仍然只能控制工具窗口第一次出现的位置。之后,该位置将始终来自用户移动工具窗口的位置,并且这是非常不可覆盖的。
不过我可能会错过一些新的 VS2010 机制。
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).
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. 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.
我似乎已经明白了:
I seem to have figured it out: