Select to view content in your preferred language

ArcGIS10 - Add Ins and Dockable Window

10524
15
08-25-2010 02:38 PM
TonyThatcher
Deactivated User
Been playing with Add-Ins in 10 using Visual Studio 10 for most of the day.  Interesting stuff.  I seem to be being pushed in this direction with the switch to .NET from VBA, so I'm just diving in. 

I have a few examples of buttons, tools, toolbars, etc. up and running, but what I really need to figure out are the Dockable Windows as part of an Add-In.  The documentation is pretty lean in this area other than saying the are "easy" using the new Add-Ins.  I have a Dockable Window added to my Add In, but I am having a heck of a time figuring out how to get it to display.  I'd like to simply click on a button and have the Dockable Window displayed.  It appears that this window should be able to hold the gammut of .NET controls, so I should be able to migrate a bit of my existing VBA Forms over to these Dockable Windows. 

Can anyone please point me in the right direction or give a sample?

Thanks much!

-Tony
0 Kudos
15 Replies
LesleyBross
Deactivated User
Here is my code for popping a Dockable Window from a Button in and add-in where 'DockableWindow1' is the class name for the dockable window class generated by the ESRI add-in wizard.

    Protected Overrides Sub OnClick()
        Dim dockWindow As ESRI.ArcGIS.Framework.IDockableWindow

        ' Only get/create the dockable window if it's not there
        If dockWindow Is Nothing Then
            Dim dockWinID As UID = New UIDClass()
            dockWinID.Value = My.ThisAddIn.IDs.DockableWindow1
            dockWindow = My.ArcMap.DockableWindowManager.GetDockableWindow(dockWinID)
        End If
        dockWindow.Show((Not dockWindow.IsVisible()))
    End Sub
0 Kudos
TonyThatcher
Deactivated User
Lesley-
Thanks much.  Pretty simple now that I see an example.  One question.  I am getting an error regarding the UID (Type 'UID' is not defined.).  I seem to be missing a reference to somenthing.  Any ideas?  See attached image.



-Tony
0 Kudos
TonyThatcher
Deactivated User
Hah!  Got it!  Just needed to add 'Imports ESRI.ArcGIS.esriSystem' to the top of the code.

Again, many thanks!  Works like a charm.

-T
0 Kudos
JasonMiller
Deactivated User
Does anyone have this code in C#?

JMiller
0 Kudos
JohnHauck
Frequent Contributor
Here is the code in C#:

       
UID dockWinID = new UIDClass();
dockWinID.Value = ThisAddIn.IDs.DockableWindow1;

// Use GetDockableWindow directly as we want the client IDockableWindow not the internal class
IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID);
dockWindow.Show(true);
0 Kudos
RyanClark
Deactivated User
When should the form itself be getting initialized? I've used the code provided here to open up my dockable window, but when it opens I don't see any of the controls that I placed in the UserControl. The InitializeComponent() method is never getting called...

...
    protected override void OnClick()
        {
            UID theUid = new UIDClass();            
            theUid.Value = ThisAddIn.IDs.dwnMapUnitLegendEditor;

            IDockableWindow mapUnitForm = ArcMap.DockableWindowManager.GetDockableWindow(theUid);           
            mapUnitForm.Show(true);
        }
...

    /// <summary>
    /// Designer class of the dockable window add-in. It contains user interfaces that
    /// make up the dockable window.
    /// </summary>
    public partial class dwnMapUnitLegendEditor : UserControl
    {
        public dwnMapUnitLegendEditor(object hook)
        {
            InitializeComponent();
            this.Hook = hook;
        }

        /// <summary>
        /// Host object of the dockable window
        /// </summary>
        private object Hook
        {
            get;
            set;
        }

        /// <summary>
        /// Implementation class of the dockable window add-in. It is responsible for 
        /// creating and disposing the user interface class of the dockable window.
        /// </summary>
        public class AddinImpl : ESRI.ArcGIS.Desktop.AddIns.DockableWindow
        {
            private dwnMapUnitLegendEditor m_windowUI;

            public AddinImpl()
            {
                Console.Write("Something");
            }

            protected override IntPtr OnCreateChild()
            {
                m_windowUI = new dwnMapUnitLegendEditor(this.Hook);
                return m_windowUI.Handle;
            }

            protected override void Dispose(bool disposing)
            {
                if (m_windowUI != null)
                    m_windowUI.Dispose(disposing);

                base.Dispose(disposing);
            }

        }
0 Kudos
RyanClark
Deactivated User
Is it possible to change the width of the dockable window programmatically once it has been initialized? I can change the width of the UserControl just fine, but the dockable window retains its size...

Thanks,
Ryan
0 Kudos
CraigPerreault
Deactivated User
I have the property Locked = True in my DockableWindow but the user can still resize it.
Can we control the size of the Dockable Window?
0 Kudos
SteveFang
Deactivated User
Look at IWindowPosition interface if you want to adjust the size of a dockable window programmatically.
0 Kudos