Normally, in ArcMap, when an event handler to catch the FocusMapChanged event is set up, and a new map (data frame) is activated, when the event fires, a reference to the FocusMap returns the map that is being activated. BUT, when the currently active map is removed from the document, when the event fires, a reference to the FocusMap returns the map that is being removed! What?! This behaviour is not helpful to me.
Here's code that displays a message box with the name of the Focus Map whenever the FocusMapChanged event fires...
Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.ArcMapUI Public Class test_FocusMapChanged Inherits ESRI.ArcGIS.Desktop.AddIns.Button Private m_FocusMapChanged Private activeViewEventsPL As IActiveViewEvents_Event Private Sub ActiveViewEventsHandler(ByVal map As IMxDocument) activeViewEventsPL = TryCast(map.PageLayout, IActiveViewEvents_Event) m_FocusMapChanged = New IActiveViewEvents_FocusMapChangedEventHandler(AddressOf FocusMapChanged) AddHandler activeViewEventsPL.FocusMapChanged, m_FocusMapChanged End Sub Private Sub FocusMapChanged() MsgBox(My.ArcMap.Document.ActiveView.FocusMap.Name) End Sub Protected Overrides Sub OnClick() ActiveViewEventsHandler(My.ArcMap.Document) End Sub
Does anyone have any ideas of how to get around this and get a reference to the newly activated map rather than the removed map?