Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics.DrawRectangle(Pen, RectangleF)

http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawrectangle.aspx

FillRectangle, DrawRectangle, FillElipse and DrawEllipse all can take 4 Float (or "Single") parameters: x, y, width, height. DrawRectangle is the only one that will not take a RectangleF, though.

I was wondering if anyone knew why this is. It sure seems like they just plain forgot to overload it.

like image 547
Mike Avatar asked Jan 20 '09 20:01

Mike


2 Answers

Well it sure does look like an omission to me too.

Interestingly, there is an overload of DrawRectangles that takes a RectangleF[] array as a parameter.

So I suppose you could use this with an array size of one if needed.

like image 65
Andy Avatar answered Oct 14 '22 15:10

Andy


According to the Andy's answer the extension should be as below

public static class GraphicsExtensions
{
    public static void DrawRectangle(this Graphics g, Pen pen, RectangleF rect)
    {
        g.DrawRectangles(pen, new[] { rect });
    }
}
like image 24
Tourmalin Avatar answered Oct 14 '22 14:10

Tourmalin