Graphics.DrawRectangle(Pen, RectangleF)
-
19-08-2019 - |
题
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawrectangle.aspx
FillRectangle、DrawRectangle、FillElipse 和 DrawEllipse 都可以采用 4 个 Float(或“Single”)参数:x、y、宽度、高度。不过,DrawRectangle 是唯一一个不采用 RectangleF 的函数。
我想知道是否有人知道这是为什么。看来他们只是忘记超载了。
解决方案
那么它肯定看起来像遗漏对我来说太。
有趣的是,存在需要的RectangleF []数组作为参数DrawRectangles的过载。
因此,我想,如果需要,你可以使用一个阵列大小使用此
其他提示
按照Andy的答案扩展名应该是如以下
public static class GraphicsExtensions
{
public static void DrawRectangle(this Graphics g, Pen pen, RectangleF rect)
{
g.DrawRectangles(pen, new[] { rect });
}
}
这是安迪的回答继,这个简单的扩展方法,使生活更轻松。
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);
}
不隶属于 StackOverflow