如果 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 不是。
感谢您的帮助!