Here is a working solution as I got it from
stackoverflow.com here:
If you are using the ContextMenuStrip class which replaces and adds functionality to the ContextMenu control of previous versions, you can use a similar code:
For Each x As Object In Me.components.Components
If TypeOf x Is ContextMenuStrip Then
MsgBox(CType(x, ContextMenuStrip).Name)
End If
Next x
You need to use Reflection in order to find every ContextMenuStrip in the collection of open forms owned by the application.
For Each frm As Form In My.Application.OpenForms
For Each fi As System.Reflection.FieldInfo In frm.GetType.GetFields(
System.Reflection.BindingFlags.NonPublic Or _
System.Reflection.BindingFlags.Instance Or _
System.Reflection.BindingFlags.DeclaredOnly)
If fi.FieldType Is GetType(ContextMenuStrip) Then
MsgBox(frm.Name & " - " & TryCast(fi.GetValue(frm), ContextMenuStrip).Name)
End If
Next fi
Next frm
And in case we use a
MetroContextMenu control, we should replace every:
ContextMenuStrip
to:
MetroFramework.Controls.MetroContextMenu