locked
How to set size of a Window Package RRS feed

  • Question

  • Hey there,

    I work on a Window Tool Package in VSX and I would like to set the size of the window during runtime.

    How can I do that?
    I can't figure it out, because I'm fairly new to VSX and it seams that I have only control over my window-tool-control during runtime and nothing more, but that's not enough.
    Friday, June 5, 2009 9:36 AM

Answers

  • The initial state (docked, floating, etc) as well as site (if floating) can be dictated by the ProvideToolWindow attribute. Thereafter, the window's state, size, position are stored in the users .vssettings file.

    You can programatically set the size, position, or state through the toolwindow's IVsWindowFrame interface. Invoking the SetFramePos method should do the trick.

    Note, getting the IVsWindowFrame interface can be a little tricky. You have to query for the SVsWindowFrame service on the IServiceProvider passed to your toolwindow's IVsWindowPane.SetSite implementation. If you are using an MPF based toolwindow, you can use the ToolWindowPane.Frame property, but only after the OnToolWindowCreated method has been called (to ensure the toolwindow has been sited).

    Just cast the object returned by the Frame property to an IVsWindowFrame, and you should be good to go.


    Ed Dore
    Friday, June 5, 2009 4:12 PM
  • Hello,

    Sorry for late reply.

    What Ed suggested is the basic idea to get the IVsWindowFrame interface and call the SetFramePos method.  For example, if you are using MPF, you could add below code to resize your toolwindow in your Package base class:

    Guid nullGuid = Guid.Empty;
    ToolWindowPane window = this.FindToolWindow(typeof(YourToolWindowClass), 0, true);
    if ((null == window) || (null == window.Frame))
    {
        throw new NotSupportedException(Resources.CanNotCreateWindow);
    }
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
    windowFrame.SetFramePos(VSSETFRAMEPOS.SFP_fSize, ref nullGuid, 5, 5, 305, 305);
    


    Please note that the call to SetFramePos should be performed after Show() method is invoked.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Edited by Wesley Yao Thursday, June 18, 2009 11:46 AM
    • Marked as answer by Wesley Yao Friday, June 19, 2009 4:59 AM
    Thursday, June 18, 2009 10:59 AM

All replies

  • The initial state (docked, floating, etc) as well as site (if floating) can be dictated by the ProvideToolWindow attribute. Thereafter, the window's state, size, position are stored in the users .vssettings file.

    You can programatically set the size, position, or state through the toolwindow's IVsWindowFrame interface. Invoking the SetFramePos method should do the trick.

    Note, getting the IVsWindowFrame interface can be a little tricky. You have to query for the SVsWindowFrame service on the IServiceProvider passed to your toolwindow's IVsWindowPane.SetSite implementation. If you are using an MPF based toolwindow, you can use the ToolWindowPane.Frame property, but only after the OnToolWindowCreated method has been called (to ensure the toolwindow has been sited).

    Just cast the object returned by the Frame property to an IVsWindowFrame, and you should be good to go.


    Ed Dore
    Friday, June 5, 2009 4:12 PM
  • oh my... sorry but I don't understand it.

    "You have to query for the SVsWindowFrame service on the IServiceProvider passed to your toolwindow's IVsWindowPane.SetSite implementation."
    .but how do I query? and who gets the IVsWindowFrame? Is it the MyToolWindow.cs file? -.-
    Monday, June 8, 2009 8:33 PM
  • Hello,

    Sorry for late reply.

    What Ed suggested is the basic idea to get the IVsWindowFrame interface and call the SetFramePos method.  For example, if you are using MPF, you could add below code to resize your toolwindow in your Package base class:

    Guid nullGuid = Guid.Empty;
    ToolWindowPane window = this.FindToolWindow(typeof(YourToolWindowClass), 0, true);
    if ((null == window) || (null == window.Frame))
    {
        throw new NotSupportedException(Resources.CanNotCreateWindow);
    }
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
    windowFrame.SetFramePos(VSSETFRAMEPOS.SFP_fSize, ref nullGuid, 5, 5, 305, 305);
    


    Please note that the call to SetFramePos should be performed after Show() method is invoked.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Edited by Wesley Yao Thursday, June 18, 2009 11:46 AM
    • Marked as answer by Wesley Yao Friday, June 19, 2009 4:59 AM
    Thursday, June 18, 2009 10:59 AM