I have an ArcMap 10.x AddIn in which I've developed a dockable window. Everything works great except that I want the dockable window to be closed when ArcMap first starts. If the user closes ArcMap with my dockable window open, ArcMap remembers its state and opens it again when it is next launched.

The following code works to open or close the dockable window once ArcMap is open:

Dim pUI As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UID
pUI.Value = My.ThisAddIn.IDs.CenterlineDockableWindow

Dim docWin As ESRI.ArcGIS.Framework.IDockableWindow = My.ArcMap.DockableWindowManager.GetDockableWindow(pUI)
If TypeOf docWin Is ESRI.ArcGIS.Framework.IDockableWindow Then
End If

But I have tried calling this code all over the place and I can't get my dockable window to close at the start of an ArcMap session. (Addin extension startup, construction of the dockable window.) Help please!

1 Answer 1


The way I have done this in the past is to put the code to close the window in the close document event. So you need to set up a document event handler to catch the close document event:

Private m_CloseDocument

Private Sub DocumentEventsHandler(ByVal doc As IMxDocument)
    If doc is Nothing Then
    End If

    Dim documentEvents = TryCast(doc, IDocumentEvents_Event)

    m_CloseDocument = New IDocumentEvents_CloseDocumentEventHandler(AddressOf CloseDocument)
    AddHandler documentEvents.CloseDocument, m_CloseDocument
End Sub

When the form loads, wire up the document event handler:

Private Sub CenterlineDockableWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

The following code will fire when the document is closed:

Private Sub CloseDocument()
End Sub

One thing to be aware of is that this can sometmies fail if ArcMap shuts down incorrectly, ie the program crashes or hangs and needs to be terminated.

More about the IDocumentEvents interface here: http://resources.arcgis.com/en/help/arcobjects-net/componenthelp/index.html#//000v000000nn000000

  • This works. Thanks! It never occurred to me to close the dockable window as ArcMap closes rather than when it opens. Given the obtuse sequence of events to create a dockable window object it makes tons of sense to perform the close when the object is in a stable state, just before close. It also has the desirable effect of closing the dockable window when a new ArcMap document is opened. Fantastic!
    – narmaps
    Commented May 15, 2015 at 15:34
  • Excellent, glad it is working! Please consider marking this as answered, if you believe it to be, that way it is removed from the list of unanswered questions. Thanks. Commented May 15, 2015 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.