Community
Showing results for 
Search instead for 
Do you mean 
Reply

Menu Item icon

Accepted Solution Solved
Copper Contributor
Posts: 21
Country: United Kingdom
Accepted Solution

Menu Item icon

Hi

 

I would like to add an icon to a menu item. This is how I'm currently adding the item to the Tools Menu: -

 

_Instance.Explorer.CreateMenuItem(Author, "", AuthorMenuURN, ToolsMenu, True, "")

 

I can see that the last parameter for CreateMenuItem is "iconResourceName". Could anyone explain how to use it?

 

Thanks.

Luke

 


Accepted Solutions
Solution
Accepted by topic author lukedev
‎09-25-2015 03:20 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Menu Item icon

There is an older example on how to add a menu item in the act! SDK documentaion.

I have long since modified the original code from that documentaion.

 

Here is what I use today in Impact Suite.

 

  ' Add a menu item under the TOOLS/DURKIN
    Public Shared Sub AddMenuItem(ByVal urn As String, _
                                  ByVal MenuText As String, _
                                  ByVal Handler As Act.UI.CommandHandler, _
                                  ByVal ACTAPP As Act.UI.ActApplication, _
                                  ByVal Position As Integer, _
                                  ByVal HasSeperator As Boolean, _
                                  ByVal ico As System.Drawing.Icon)

        '-----------------------------------------------------
        ' DEV 5.1.0.10
        ' Adds a menu item that delegates back to us 
        '-----------------------------------------------------

        '-----------------------------------------------------
        ' Check if the connected menus exists
        '-----------------------------------------------------
        If ACTAPP.Explorer.CommandBarCollection("Connected Menus") Is Nothing Then
            Return
        End If

        '-----------------------------------------------------
        ' Remove the menu item
        '-----------------------------------------------------
        If (MenuItemExists(urn, ACTAPP) = True) Then
            RemoveMenuItem(urn, ACTAPP)
        End If

        Try

            '-----------------------------------------------------
            ' Get the parent menu
            '-----------------------------------------------------
            Dim ParentMenu As Act.UI.Core.CommandBarControl
            ParentMenu = CType(ACTAPP.Explorer.CommandBarCollection("Connected Menus").ControlCollection(GetParentControlURN(urn)), Act.UI.Core.CommandBarControl)

            '-----------------------------------------------------
            ' Create a new menu
            '-----------------------------------------------------
            Dim NewMenu As Act.UI.Core.CommandBarButton
            NewMenu = New Act.UI.Core.CommandBarButton(MenuText, MenuText, Nothing, urn, Nothing, Nothing)

            '-----------------------------------------------------
            ' Register the command to be raised back to us
            '-----------------------------------------------------
            ACTAPP.RegisterCommand(urn, Handler, Act.UI.RegisterType.Shell)

            '-----------------------------------------------------
            ' Are we displaying an icon
            '-----------------------------------------------------
            If Not ico Is Nothing Then
                NewMenu.Icon = ico
                NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.ImageAndText
            Else
                NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly
            End If

            '-----------------------------------------------------
            ' IF we are the first addon under "About Durkin Computing"
            ' the add the seperator
            '-----------------------------------------------------
            If Not (ParentMenu Is Nothing) Then
                If ParentMenu.SubItems.Length = 1 Then
                    NewMenu.HasSeparator = True
                Else
                    NewMenu.HasSeparator = HasSeperator
                End If

                '-----------------------------------------------------
                ' Set the position if other then 0 ( 0= at the bottom )
                '-----------------------------------------------------
                If Position = 0 Then
                    ParentMenu.AddSubItem(NewMenu)
                Else
                    ParentMenu.AddSubItem(NewMenu, Position)
                End If
            End If


        Catch ex As Exception
            Throw New Exception("ACTAPPFunctions:AddMenuItem:2", ex)
        End Try

    End Sub  'AddMenuItem

 

 

Hope this helps

-- Jim Durkin

 

 

View solution in original post


All Replies
Solution
Accepted by topic author lukedev
‎09-25-2015 03:20 AM
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Menu Item icon

There is an older example on how to add a menu item in the act! SDK documentaion.

I have long since modified the original code from that documentaion.

 

Here is what I use today in Impact Suite.

 

  ' Add a menu item under the TOOLS/DURKIN
    Public Shared Sub AddMenuItem(ByVal urn As String, _
                                  ByVal MenuText As String, _
                                  ByVal Handler As Act.UI.CommandHandler, _
                                  ByVal ACTAPP As Act.UI.ActApplication, _
                                  ByVal Position As Integer, _
                                  ByVal HasSeperator As Boolean, _
                                  ByVal ico As System.Drawing.Icon)

        '-----------------------------------------------------
        ' DEV 5.1.0.10
        ' Adds a menu item that delegates back to us 
        '-----------------------------------------------------

        '-----------------------------------------------------
        ' Check if the connected menus exists
        '-----------------------------------------------------
        If ACTAPP.Explorer.CommandBarCollection("Connected Menus") Is Nothing Then
            Return
        End If

        '-----------------------------------------------------
        ' Remove the menu item
        '-----------------------------------------------------
        If (MenuItemExists(urn, ACTAPP) = True) Then
            RemoveMenuItem(urn, ACTAPP)
        End If

        Try

            '-----------------------------------------------------
            ' Get the parent menu
            '-----------------------------------------------------
            Dim ParentMenu As Act.UI.Core.CommandBarControl
            ParentMenu = CType(ACTAPP.Explorer.CommandBarCollection("Connected Menus").ControlCollection(GetParentControlURN(urn)), Act.UI.Core.CommandBarControl)

            '-----------------------------------------------------
            ' Create a new menu
            '-----------------------------------------------------
            Dim NewMenu As Act.UI.Core.CommandBarButton
            NewMenu = New Act.UI.Core.CommandBarButton(MenuText, MenuText, Nothing, urn, Nothing, Nothing)

            '-----------------------------------------------------
            ' Register the command to be raised back to us
            '-----------------------------------------------------
            ACTAPP.RegisterCommand(urn, Handler, Act.UI.RegisterType.Shell)

            '-----------------------------------------------------
            ' Are we displaying an icon
            '-----------------------------------------------------
            If Not ico Is Nothing Then
                NewMenu.Icon = ico
                NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.ImageAndText
            Else
                NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly
            End If

            '-----------------------------------------------------
            ' IF we are the first addon under "About Durkin Computing"
            ' the add the seperator
            '-----------------------------------------------------
            If Not (ParentMenu Is Nothing) Then
                If ParentMenu.SubItems.Length = 1 Then
                    NewMenu.HasSeparator = True
                Else
                    NewMenu.HasSeparator = HasSeperator
                End If

                '-----------------------------------------------------
                ' Set the position if other then 0 ( 0= at the bottom )
                '-----------------------------------------------------
                If Position = 0 Then
                    ParentMenu.AddSubItem(NewMenu)
                Else
                    ParentMenu.AddSubItem(NewMenu, Position)
                End If
            End If


        Catch ex As Exception
            Throw New Exception("ACTAPPFunctions:AddMenuItem:2", ex)
        End Try

    End Sub  'AddMenuItem

 

 

Hope this helps

-- Jim Durkin

 

 

Copper Contributor
Posts: 21
Country: United Kingdom

Re: Menu Item icon

Works great - everything I needed!

 

Many thanks.

Luke