Is There Any Way to an Addin DockableWindow to IDockableWindow?

488
1
11-02-2011 02:17 PM
RichardFairhurst
MVP Honored Contributor
The AddIn DockableWindow has no properties for adjusting the frame location beyond the initial position listed in the XML file that first creates the object.  The AddIn DockableWindow fires Layout and Resize events that I can detect, but I cannot seem to intercept them and modify the behavior.  I want to access the kinds of properties available in the IWindowPosition (ESRI.ArcGIS.Framework.IWindowPosition) for an AddIn IDockableWindow (ESRI.ArcGIS.Desktop.AddIns.DockableWindow) after it is created, but can't find any way to cast it to that object or one like it.  IWindowPosition can cast an object of IDockableWindow (ESRI.ArcGIS.Framework.IDockableWindow), which seems like it should be related, but I cannot find any inheritance commonality.

Is there a way to access the AddIn DockableWindow's position properties after it has been created when the user triggers a Layout or Resize event?  If not I think I have to go with a standard Windows Form to avoid users hiding my Form controls and not knowing what to do.
0 Kudos
1 Reply
RichardFairhurst
MVP Honored Contributor
I found a method for casting the AddIn DockableWindow to an IDockableWindow as shown below.  I want to ensure the width is at least 240 pixels and the code below works for the Floating state.  However, nothing I have tried works for any of the docked states.  Any ideas on how to stop a docked window from getting too narrow?

    Public Function GetAddInDockWindow(ByVal application As ESRI.ArcGIS.Framework.IApplication) As ESRI.ArcGIS.Framework.IDockableWindow
        Dim dockWindowManager As ESRI.ArcGIS.Framework.IDockableWindowManager = CType(application, ESRI.ArcGIS.Framework.IDockableWindowManager)
        Dim windowID As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass
        windowID.Value = My.ThisAddIn.IDs.DockWindow
        Return dockWindowManager.GetDockableWindow(windowID)
    End Function

    Private Sub DockWindow_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles Me.Layout
        Dim dockableWindow As ESRI.ArcGIS.Framework.IDockableWindow
        dockableWindow = GetAddInDockWindow(CType(m_hook, ESRI.ArcGIS.Framework.IApplication))
        Dim windowPos As ESRI.ArcGIS.Framework.IWindowPosition = CType(dockableWindow, ESRI.ArcGIS.Framework.IWindowPosition)
        If windowPos.State = ESRI.ArcGIS.Framework.esriWindowState.esriWSFloating And windowPos.Width < 240 Then
            windowPos.Move(windowPos.Left, windowPos.Top, 240, windowPos.Height) ' works
        ElseIf windowPos.Width < 240 Then
            windowPos.Width = 240 ' doesn't work nor does Move for docked windows
        End If
    End Sub
0 Kudos