views:

37

answers:

2

Looking for something like:

dim rect as system.drawing.rectangle

For each point in rect Debug.print(point.name, point.value) Next

A: 

you could write an extension method that returns you an array of the points you want. I don't really do VB, but an example in C# would be something like...

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());
    }
}
Joshua Evensen
Thanks, I can use this but still holding out for way to do it without my own function. This is the system.drawing namespace rectangle object -- how can there be no built-in way to loop through the points?
pghcpa
http://msdn.microsoft.com/en-us/library/system.drawing.rectangle_members.aspx
Joshua Evensen
Check that yourself. There is no built in "GetPoints" method or anything. Why would there be? It isn't really a particularly common operation.
Joshua Evensen
A: 
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

(Line continuation added to support older versions of VB.NET)

Larsenal
arent your x and y flipped?
Joshua Evensen
Yes, how embarrassing. Fixed.
Larsenal