Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 为什么在表单中找不到上下文菜单条?_Vb.net_Object_Controls - Fatal编程技术网

Vb.net 为什么在表单中找不到上下文菜单条?

Vb.net 为什么在表单中找不到上下文菜单条?,vb.net,object,controls,Vb.net,Object,Controls,我正在尝试在表单中查找上下文菜单条,但我的代码似乎没有显示我所需的输出…以下是我的代码: Dim omnuStrip() As Object = oCollection.controls.find("mnuStrip", True) Dim mnuStrip_ as ContextMenuStrip = DirectCast(omnuStrip,ContextMenuStrip) mnuStrip_.Tag = "My Control" 它总是返回一个空的对象数组…我在这里做错了吗?请帮忙……

我正在尝试在表单中查找上下文菜单条,但我的代码似乎没有显示我所需的输出…以下是我的代码:

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

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

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

另一件事…UserControl也有组件吗?例如,oComponents是一个UserControl而不是Windows窗体。