http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawrectangle.aspx
FillRectangle、DrawRectangle、FillElipse和DrawEllipse都可以接受4个浮动(或“单一”)参数: x,y,width,height。不过,DrawRectangle是唯一一家不接受RectangleF考试的公司。
我想知道有没有人知道为什么。看起来他们就是忘了超载。
发布于 2009-01-21 21:21:31
嗯,在我看来,这也确实是一个疏漏。
有趣的是,有一个以RectangleF[]数组为参数的DrawRectangles重载。
所以如果需要的话,我想你可以使用数组大小为1的数组。
发布于 2018-03-27 13:17:12
根据Andy的回答,扩展应该如下所示
public static class GraphicsExtensions
{
public static void DrawRectangle(this Graphics g, Pen pen, RectangleF rect)
{
g.DrawRectangles(pen, new[] { rect });
}
}发布于 2017-08-23 15:42:50
根据Andy的回答,这个简单的扩展方法让生活变得更容易。
using System.Drawing;
public static class GraphicsExtensions
{
public static void DrawRectangle(this Graphics g, Pen pen, RectangleF rect) =>
g.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
}https://stackoverflow.com/questions/462995
复制相似问题