我试图在我的表单中找到我的上下文菜单条,但我的代码似乎没有显示我想要的输出...这是我的代码:
Dim omnuStrip() As Object = oCollection.controls.find("mnuStrip", True)
Dim mnuStrip_ as ContextMenuStrip = DirectCast(omnuStrip,ContextMenuStrip)
mnuStrip_.Tag = "My Control"
它总是返回一个空的对象数组......我在这里做错了吗?请帮忙......谢谢!
答案 0 :(得分:1)
ContextMenuStrips被添加到组件,而不是控件,这就是为什么你得到一个空数组。
Dim strip As ContextMenuStrip = Nothing
For Each component As Object In components.Components
strip = TryCast(component, ContextMenuStrip)
If strip IsNot Nothing Then Exit For
Next