Select to view content in your preferred language

Cannot Select Layout Elements Upon Closing Windows Form

2138
5
Jump to solution
01-28-2013 02:25 PM
RichardFairhurst
MVP Honored Contributor
I have an Add-In that contains a button that launches a Windows Form as a Modal Dialog (ShowDialog).  When I close the form (whether or not I have caused the form to run any code beyond launching itself), I am unable to select any Layout Elements (i.e., Data Frame, Title Text, Scale Bar, North Arrow, Drawn Graphics, etc).  The Layout elements can only be selected again if I press the Layout View menu item again on the View Menu, or switch back and forth between Data View and Layout View.

The form only has Radio Buttons and Cammond Buttons and no code is loaded at start up other than to initialize a module level MxDocument variable.  The Cancel button does a ReleaseComObject of the module level variables and then a Me.Close.  After the Dialog closes itself the start-up add-in button processes Dispose on the form.  I don't know of any way to avoid this behavior.

I am using 10.1 SP1.  The behavoir also occurred when I was running 10.0.  Has anyone else experienced this?  Does anyone have a fix beyond the work around I mentioned?  Thanks.
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
In Arcmap you can only have one tool active at a time, which is reflected in the ArcMap.Application.CurrentTool property.
Buttons that look depressed are simply commands that have their checked property set to true. Example of these include the editor shape constructors, the editor command on the standard toolbar and the snapping types on the snapping toolbar etc.

If you set the currenttool property to null or nothing in your add-in, like Ken does in his example, the current tool is deactivated. The arcmap cursor changes to a default which just happens to be the one used by the select elements tool, hence the confusion.

The add-in wizard template code includes this in the on-click events for buttons so in your case your button is probably deactivating the current tool before showing the modal dialog. Simply remove or comment out this line.

The customize dialog also clears the selected tool and has done so since arcgis 8.

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor
That's something I've never noticed before, but I'm getting the same issue opening a Windows form using Show.

This is the code for the button opening my form.

Public Class Aggregate
  Inherits ESRI.ArcGIS.Desktop.AddIns.Button

  Public Sub New()

  End Sub

  Protected Overrides Sub OnClick()
        Try
            Dim AggForm As New AggregateForm

            If AggForm.InitializeForm Then 'sets up the initial view of the form
                CenterForm(AggForm, My.ArcMap.Application) 'centers the form on the application window
                AggForm.Show(System.Windows.Forms.Control.FromHandle(My.ArcMap.Application.hWnd))
            End If

        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString, "OnClick")
        End Try

        '
        My.ArcMap.Application.CurrentTool = Nothing
  End Sub

  Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
  End Sub
End Class
0 Kudos
RichardFairhurst
MVP Honored Contributor
Apparently this behavior is not limited to using an Add-In or a Windows Form.  The mere act of starting and stopping Customize Mode without doing anything else causes the frozen Layout behavior.  Or just pressing a user created Add-In button on a toolbar that does absolutely nothing causes the behavior.  (Buttons created by ESRI do not seem to have this problem, just user Add-In buttons).

At this point it seems clear to me that this is a fundamental bug in the Desktop application affecting all user customizations and that it is not tied to any particular kind of user customization.  I would consider this to be a serious issue that indicates that the overhaul of user customizations that occured in 10.0+ was poorly implemented compared to previous versions.
0 Kudos
RichardFairhurst
MVP Honored Contributor
I found out that this behavior is by design from ESRI and an �??enhancement�?�  change at 10.0 from the behavior of 9.3.  At 9.3 pressing a normal button would not deselect the Select Element button on the toolbar (the standard selection tool that is active by default when ArcGIS opens).  At 10.0+ pressing any button does deselect the Select Elements button.  Why?  I don�??t know.

In versions previous to ArcGIS 10.0 the Select Element button has only been unselected by tools that stay depressed on the toolbar and that changed the cursor shape (both visual cues that the Select Elements button was no longer selected).  However, before 10.0 it did not do this for regular buttons where the new button does not stay depressed and the cursor does not change (giving no visual cues to the user that they did anything to affect the Select Elements button). 

I have told ESRI that I think this is a dumb enhancement and that it just adds a pointless extra mouse click and confusion to users that have no reason to look over and notice the subtle behavior of the Select Element button becoming unselected when they press a button that may be located nowhere near the Select Elements button.  Because the Select Elements button has always been and continues to be a default option at start-up, almost none of my basic viewer users have ever actually clicked this button before or were even really aware of its existence.

So the workaround is to press the Select Elements Button after running any tool or button on the toolbar.  The same applies to opening the Customize Mode dialog and probably many other menu items.

Now that I know what behavior ESRI changed with their "enhancement" I can write code to undo their change when my buttons finish, since I have no reason to want the Select Elements button to not work.
0 Kudos
by Anonymous User
Not applicable
In Arcmap you can only have one tool active at a time, which is reflected in the ArcMap.Application.CurrentTool property.
Buttons that look depressed are simply commands that have their checked property set to true. Example of these include the editor shape constructors, the editor command on the standard toolbar and the snapping types on the snapping toolbar etc.

If you set the currenttool property to null or nothing in your add-in, like Ken does in his example, the current tool is deactivated. The arcmap cursor changes to a default which just happens to be the one used by the select elements tool, hence the confusion.

The add-in wizard template code includes this in the on-click events for buttons so in your case your button is probably deactivating the current tool before showing the modal dialog. Simply remove or comment out this line.

The customize dialog also clears the selected tool and has done so since arcgis 8.
0 Kudos
RichardFairhurst
MVP Honored Contributor
In Arcmap you can only have one tool active at a time, which is reflected in the ArcMap.Application.CurrentTool property.
Buttons that look depressed are simply commands that have their checked property set to true. Example of these include the editor shape constructors, the editor command on the standard toolbar and the snapping types on the snapping toolbar etc.

If you set the currenttool property to null or nothing in your add-in, like Ken does in his example, the current tool is deactivated. The arcmap cursor changes to a default which just happens to be the one used by the select elements tool, hence the confusion.

The add-in wizard template code includes this in the on-click events for buttons so in your case your button is probably deactivating the current tool before showing the modal dialog. Simply remove or comment out this line.

The customize dialog also clears the selected tool and has done so since arcgis 8.


Got it.  I had not really paid attention to or thought through what the default code for the onClick button was actually doing, since I just assumed it was was there by default to only deselect the button that I was creating rather than every button in ArcMap.  For my buttons I will comment out the line that reads:

My.ArcMap.Application.CurrentTool = Nothing

It would be nice if the default code above had a comment explaining what it does, such as:

' Unselect all buttons and tools on all toolbars.
0 Kudos