1

如果 ContextMenuStrip 存在于表单上,我需要对其进行处理。

因此我尝试了

    For Each c As Control In uForm.Controls
        If TypeOf c Is ContextMenuStrip Then

            Dim n As ContextMenuStrip
            n = DirectCast(c, ContextMenuStrip)

            For Each c2 As ToolStripMenuItem In n.Items
                MsgBox(c2.Text)
            Next
        End If
    Next

但是,当我遍历控件时,ContextMenuStrip 并不“存在”。例如,当我在表单上放置一个按钮时,使用上述迭代找到该按钮。但 ContextMenuStrip 不是。

感谢您的帮助!

4

1 回答 1

1

像这样试试

For Each c As Control In uForm.components.Components

        If TypeOf c Is ContextMenuStrip Then

            Dim n As ContextMenuStrip
            n = DirectCast(c, ContextMenuStrip)

            For Each c2 As ToolStripMenuItem In n.Items
                MsgBox(c2.Text)
            Next
        End If

    Next

我测试过 像这样:这是你想要的吗?

   For Each c As Control In Me.components.Components

            If TypeOf c Is ContextMenuStrip Then
                MsgBox("sadfsadfsd")
            End If

        Next
于 2014-02-11T12:20:05.993 回答