0

我试图在我的表单中找到我的上下文菜单条,但我的代码似乎没有显示我想要的输出......这是我的代码:

Dim omnuStrip() As Object = oCollection.controls.find("mnuStrip", True)
Dim mnuStrip_ as ContextMenuStrip = DirectCast(omnuStrip,ContextMenuStrip)
mnuStrip_.Tag = "My Control"

它总是返回一个空的对象数组......我在这里做错了吗?请帮忙..谢谢!

4

1 回答 1

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
于 2012-06-05T06:37:06.123 回答