none
Communicating with the winforms designer RRS feed

  • Question

  • Hi!

    My situation is as follows:
    a)i'm making a visual studio integration package which consists of a tool window that has to be visible only when the windows forms designer is active.
    b)The toolwindow also needs to be able to iterate through the controls on the design surface of the winforms designer.
    c)i'm not getting anywhere and am doubting my decision to become a programmer instead of a pop-singer or a gardenerSmile

    My question: How do I ask VS to give me a reference to the designer(or design surface maybe) so i can iterate through the controls on it? What service do i ask for, what interface do i cast the result to. I don't even know where to start with this. Can this be done? Does IActiveDesigner interface have enything to do with this? I'm stuck with this, it's very frustratingSad

    Thx!
    Antonio
    Thursday, November 15, 2007 2:49 PM

Answers

All replies

  • See:

     

    HOWTO: Manipulating controls of Windows forms from Visual Studio .NET add-ins.

    http://www.mztools.com/resources_vsnet_addins.aspx

     

    You can use the DTE object from a package using GetService(typeof EnvDTE.DTE)

     

    Friday, November 16, 2007 10:07 AM
    Moderator
  • Hi Carlos!

    Thx a bunch, that helped a lot!

    This is what I came up with in the end:

    DTE2 appObj = (DTE2)GetService(typeof(DTE));
    Document doc = appObj.ActiveDocument;
    IDesignerHost designerHost = appObj.ActiveDocument.ActiveWindow.Object as IDesignerHost;
    Control rootControl = designerHost.Container.Components[0] as Control;

    To anyone that might find this useful, the DTE and DTE2 can be referenced as described in this article:
    http://msdn2.microsoft.com/en-us/library/t6d9sf9k(VS.80).aspx


    Friday, November 16, 2007 3:27 PM