Author Topic: ContextMenu from StatusBar (trayitem)  (Read 3512 times)

0 Members and 1 Guest are viewing this topic.

Chumplybum

  • Newt
  • Posts: 97
ContextMenu from StatusBar (trayitem)
« on: October 10, 2011, 09:14:02 PM »
Hi,

i'm having some trouble getting the event handler to fire for a menuitem attached to a trayitem in the statusbar, searching the internet i've found this http://forums.autodesk.com/t5/forums/mobileforumtopicpage/board-id/152/thread-id/17250 from the autodesk discussion groups which from the looks of it is the exact problem i'm having as well... but with no solution.

Code: [Select]

Public Class NewClass

#Region " Implements "

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

#Region " IExtensionApplication "

    Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
   
    Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.TrayItems.Add(Me.TrayItem)
        Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update()

    End Sub

    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
    End Sub
   
    #End region
#End Region


<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
    Private m_TrayItem As Autodesk.AutoCAD.Windows.TrayItem = Nothing
    ''' <summary>
    '''
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property TrayItem As Autodesk.AutoCAD.Windows.TrayItem
        Get
            If Me.m_TrayItem Is Nothing Then
                Me.m_TrayItem = New Autodesk.AutoCAD.Windows.TrayItem
                Me.m_TrayItem.Icon = System.Drawing.SystemIcons.Asterisk
                Me.m_TrayItem.ToolTipText = "Testing"
                Me.m_TrayItem.Visible = True

                AddHandler m_TrayItem.MouseDown, AddressOf callback_MouseDown
            End If
            Return Me.m_TrayItem
        End Get
    End Property
   
   
    <DebuggerBrowsable(DebuggerBrowsableState.Never)> _
    Private m_ContextMenu As System.Windows.Forms.ContextMenu = Nothing
    ''' <summary>
    '''
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private ReadOnly Property ContextMenu() As System.Windows.Forms.ContextMenu
        Get
            If Me.m_ContextMenu Is Nothing Then
                Me.m_ContextMenu = New System.Windows.Forms.ContextMenu
                Dim MenuItem1 As New System.Windows.Forms.MenuItem("MenuItem1")
                AddHandler MenuItem1.Click, AddressOf MenuItem1_Click
                Dim MenuItem2 As New System.Windows.Forms.MenuItem("MenuItem2...")
                AddHandler MenuItem2.Click, AddressOf MenuItem2_Click
                Dim MenuItem3 As New System.Windows.Forms.MenuItem("MenuItem3...")
                AddHandler MenuItem3.Click, AddressOf MenuItem3_Click

                Me.m_ContextMenu.MenuItems.Add(MenuItem1)
                Me.m_ContextMenu.MenuItems.Add(MenuItem2)
                Me.m_ContextMenu.MenuItems.Add(New System.Windows.Forms.MenuItem("-"))
                Me.m_ContextMenu.MenuItems.Add(MenuItem3)
            End If
            Return Me.m_ContextMenu
        End Get
    End Property
   
   
   
#Region " TrayItem "

    Private Sub callback_MouseDown(ByVal sender As Object, ByVal e As Autodesk.autocad.windows.StatusBarMouseDownEventArgs)
        Try
            Select Case e.Button
            Case Windows.Forms.MouseButtons.Left
            WriteMsg("left button")

                Case Windows.Forms.MouseButtons.Right
                    Dim ti As Autodesk.AutoCAD.Windows.TrayItem = CType(sender, Autodesk.AutoCAD.Windows.TrayItem)
                    ti.DisplayContextMenu(Me.ContextMenu, New System.Drawing.Point(e.X, e.Y))

            End Select
        Catch ex As System.Exception
        End Try
    End Sub

#Region " Context Menu "

    Private Sub MenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    WriteMsg("MenuItem1")
    End Sub

    Private Sub MenuItem2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    WriteMsg("MenuItem2")
    End Sub

    Private Sub MenuItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    WriteMsg("MenuItem3")
    End Sub

#End Region

#End Region

   
    Private Sub WriteMsg(ByVal msg As String)
   
    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Environment.NewLine & msg)
   
    End Sub

End Class


does anyone have any ideas of how i can get this to work?


thanks in advance

cheers, mark

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: ContextMenu from StatusBar (trayitem)
« Reply #1 on: October 27, 2012, 01:52:12 PM »
I have same problem. Anybody knows solution today?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: ContextMenu from StatusBar (trayitem)
« Reply #2 on: October 28, 2012, 06:09:51 AM »
Alternative variant for context menu showing, I showed here. I used WPF for solving this problem.