Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.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
是否可以使用Me.Controls.find(";,True)(0)VB.NET查找矩形形状_Vb.net - Fatal编程技术网

是否可以使用Me.Controls.find(";,True)(0)VB.NET查找矩形形状

是否可以使用Me.Controls.find(";,True)(0)VB.NET查找矩形形状,vb.net,Vb.net,p1是矩形形状的名称 c = Me.Controls.Find("a1", True)(0) ctype(c, RectangleShape).FillColor = Color.Gray 当索引超出数组边界时出现错误。矩形形状不是控件,因此Controls.Find()无法找到它。索引时将返回一个空数组kaboom。您必须使用For Each迭代ShapeContainer.Shapes集合。因此,大致上: For Each shp As Shape In ShapeContaine

p1
是矩形形状的名称

c = Me.Controls.Find("a1", True)(0)
ctype(c, RectangleShape).FillColor = Color.Gray

当索引超出数组边界时出现错误。

矩形形状不是控件,因此Controls.Find()无法找到它。索引时将返回一个空数组kaboom。您必须使用For Each迭代ShapeContainer.Shapes集合。因此,大致上:

    For Each shp As Shape In ShapeContainer1.Shapes
        If TypeOf shp Is RectangleShape AndAlso shp.Name = "a1" Then
            DirectCast(shp, RectangleShape).FillColor = Color.Gray
        End If
    Next

其中“ShapeContainer1”是作为形状主体的隐藏良好的控件。

如果名称是
p1
,为什么要查找
a1
?另外,在尝试更改其属性之前,我会执行
TryCast
并检查
Nothing