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);
}

我知道这个问题很老,但仅供参考:我相信正确的方法是使用 圆形的 或者 截短, , 例如:

Dim BBox As RectangleF = ListOfRectangleF(3)         ' get RectangleF any way you have it
Dim p As New Pen(Brushes.DarkRed)
e.Graphics.DrawRectangle(p, Rectangle.Round(ptBBox)) ' draw RectangleF using Rectangle.Round()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top