Hide  Button on Addin Toolbar (ArcGIS 10.0)

4376
11
Jump to solution
06-25-2013 01:52 AM
TereseRowekamp
New Contributor III
I'd like to hide some buttons on an addin toolbar. It appears that isn't possible - there are only Enable or Checked properties.

First question - am I missing an easy way to hide an existing button on a toolbar?

Second question - if there is no way to hide a button, does that mean I need to add/remove the button to the toolbar programatically? Can someone point me to a code sample to do this? My buttons need to be in a particular order, and the ones I need to hide/show are in the middle - is there a way to add a button in a particular location?

Thanks for any help - I've been searching for code samples and failing to find examples of what I'm trying to do.

update:
- it occurs to me now that I only need to know how to remove a button. The buttons that should be shown depend on the particular user's level of access, and I know what that is when my addin initialization code is being run. So I can create the toolbar with all the buttons, and then just remove ones that shouldn't be there if the user shouldn't have access to that option.

So I'm just looking for a code sample to show how to remove a button from a toolbar.
0 Kudos
11 Replies
TereseRowekamp
New Contributor III
Duncan, you were right. I was missing the _Event in the interface name. That took care of the error message I was getting that prevented a successful build. It took me a few more minutes to realize that I forgot to make the same change in the m_appStatusEvents = line.

Here's what I have now:

    Private m_appStatusEvents As IApplicationStatusEvents_Event


    Protected Overrides Sub OnStartup()

        m_appStatusEvents = TryCast(My.ThisApplication, IApplicationStatusEvents_Event)
        AddHandler m_appStatusEvents.Initialized, AddressOf OnInitialized

    End Sub


Private Sub OnInitialized()

clsGlobals.intUserRole = 0
If clsGlobals.intUserRole <= 1 Then  'readonly user
        HideButtons()
End If

End Sub


Private Sub HideButtons()

        Dim UID As New ESRI.ArcGIS.esriSystem.UID
        Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem

        UID.Value = My.ThisAddIn.IDs.btnPushToGeo
        commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
        commandItem.Delete()

        UID.Value = My.ThisAddIn.IDs.tolCreateNew
        commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
        commandItem.Delete()

        UID.Value = My.ThisAddIn.IDs.btnUpdateOutfallSV
        commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
        commandItem.Delete()

End Sub


(I've removed other code that OnInititalized will execute to determine the user role and assume for now that these buttons always get hidden. If I can get this part to work, I will add the extra code back in).

Here's the result:
1. Open ArcMap and show toolbar - all buttons are visible.
2. Leave toolbar open, close ArcMap, open ArcMap - buttons are hidden.
3. Close toolbar, close ArcMap - back to behavior number 1.

So, as long as ArcMap is closed with the toolbar visible, the buttons are hidden when ArcMap is re-opened. Whenever the toolbar needs to be opened by the user, the buttons are not hidden.

I guess I don't understand when OnInitialized actually gets run. But the AcmeExt example has a bunch of other checks going on to test whether Startup has run, etc. so I guess it's time to go back to that sample and keep expanding my code. Unfortunately, I'm no longer being paid to figure this out and the client was OK with the addin as delivered.

Thanks again for all of your help.
0 Kudos
AndyMorgan1
New Contributor III

Terese Rowekamp wrote:

Here's the result:
1. Open ArcMap and show toolbar - all buttons are visible.
2. Leave toolbar open, close ArcMap, open ArcMap - buttons are hidden.
3. Close toolbar, close ArcMap - back to behavior number 1.

So, as long as ArcMap is closed with the toolbar visible, the buttons are hidden when ArcMap is re-opened. Whenever the toolbar needs to be opened by the user, the buttons are not hidden.

I am stuck here, too.  Exact same issue, I want to keep a button fully hidden (not disabled) in a toolbar if the user is part of a specific Active Directory group.  The problem is that there is no event exposed in the Add-in ArcObjects API for when you make the toolbar visible if it wasn't already visible when opening ArcMap.  I would greatly appreciate any workarounds! 

0 Kudos