如何以编程方式将 ToolWindow 停靠在 Visual Studio AddIn 中

发布于 2024-12-03 22:20:17 字数 1169 浏览 3 评论 0原文

我正在开发一个 Visual Studio AddIn,它显示一个类似于常用工​​具箱的工具窗口。现在,当我打开它时,我希望它像普通的工具箱一样停靠。这是用于打开它的代码(_applicationObject_addInInstance 是从 OnConnection 参数获取的 DTE2 和 AddIn):

Windows2 wins2obj = (Windows2)_applicationObject.Windows;
Assembly asm = Assembly.GetExecutingAssembly();
string an = asm.Location;
string className = "MyAddIn.MyToolboxCtl";
object programmableObject = null;
Window windowToolWindow = wins2obj.CreateToolWindow2(_addInInstance, an,
     className, "A caption", aGuid,
    ref programmableObject);

我能够停靠此窗口,将其 IsFloating 属性设置为false 在使其可见之前:

windowToolWindow.IsFloating = false;
windowToolWindow.Visible = true;

这几乎没问题,但是窗口停靠在主窗口的下部,您通常可以在其中找到“输出”、“监视”、“调用堆栈”等窗口。有没有办法强制它在左侧(您通常会看到工具箱)打开?

编辑:

我尝试将我的窗口和工具箱窗口停靠在一起创建 LinkedWindowFrame:

Window2 w1 = (Window2)wins2obj.Item(Constants.vsWindowKindToolbox);
Window2 frame = (Window2)wins2obj.CreateLinkedWindowFrame(w1, windowToolWindow,
                        vsLinkedWindowType.vsLinkedWindowTypeTabbed);

结果在某种程度上类似于我想要实现的目标,即工具箱和我的窗口停靠在一起,但生成的窗口是浮动的而不是停靠的到主窗口的左侧。

I'm developing a Visual Studio AddIn that shows a ToolWindow similar to the usual Toolbox. Now I would like to have it docked just like the normal Toolbox when I open it. This is the code used to open it (_applicationObject and _addInInstance are the DTE2 and AddIn obtained from the OnConnection arguments):

Windows2 wins2obj = (Windows2)_applicationObject.Windows;
Assembly asm = Assembly.GetExecutingAssembly();
string an = asm.Location;
string className = "MyAddIn.MyToolboxCtl";
object programmableObject = null;
Window windowToolWindow = wins2obj.CreateToolWindow2(_addInInstance, an,
     className, "A caption", aGuid,
    ref programmableObject);

I was able to dock this window setting its IsFloating property to false before making it visible:

windowToolWindow.IsFloating = false;
windowToolWindow.Visible = true;

This is almost OK, but the windows is docked in the lower part of the main window, where you usually find the Output, Watch, Call Stack, and that kind of windows. Is there a way to force it to open on the left, where you usually see the Toolbox?

EDIT:

I tried to dock my window and the toolbox window together creating a LinkedWindowFrame:

Window2 w1 = (Window2)wins2obj.Item(Constants.vsWindowKindToolbox);
Window2 frame = (Window2)wins2obj.CreateLinkedWindowFrame(w1, windowToolWindow,
                        vsLinkedWindowType.vsLinkedWindowTypeTabbed);

The result is someway similar to what I'm trying to achieve, i.e. the Toolbox and my window are docked together, but the resulting window is floating and not docked to the left side of the main window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2024-12-10 22:20:17

I think the following link will be useful for you: How to: Change Window Characteristics
Basically you will need to create / retrieve the approprirate WindowFrame and put your window in it.
Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文