如何遍历vb.net中system.drawing.rectangle中的点

时间:2010-09-06 23:10:05

标签: vb.net system.drawing

寻找类似的东西:

dim rect as system.drawing.rectangle

对于rect中的每个点    Debug.print(point.name,point.value) 下一步

2 个答案:

答案 0 :(得分:1)

您可以编写一个扩展方法,返回您想要的点数组。我不是真的做VB,但C#中的一个例子就是......

public static class RectangleExtensions
{
    public static Point[] GetPoints(this Rectangle rect)
    {
        return new Point[]
        {
            new Point(rect.Left, rect.Top),
            new Point(rect.Right, rect.Top),
            new Point(rect.Right, rect.Bottom),
            new Point(rect.Left, rect.Bottom)
        };
    }
}

public class example
{
    public void ExampleMethod()
    {
        Rectangle rect = new Rectangle();
        foreach (Point point in rect.GetPoints())
            Console.WriteLine(point.ToString());
    }
}

答案 1 :(得分:1)

Function GetAllPoints(ByVal r As Rectangle) As Point()
    Return { _
    New Point(r.Left, r.Top), _
    New Point(r.Right, r.Top), _
    New Point(r.Left, r.Bottom), _
    New Point(r.Right, r.Bottom) _
    }
End Function

(添加了行继续以支持旧版本的VB.NET)