Reputation: 407
I have a List
with float
coordinates and I'm trying to draw a rectangle around a line previously drawn.
Graphics G = e.Graphics;
Pen pen5 = new Pen(Color.DodgerBlue, 0.01f);
var rect2 = new RectangleF();
GraphicsPath maliOkvir = new GraphicsPath();
maliOkvir.AddLine(((float)(odabraniSegment[0].startX)),
(float)(odabraniSegment[0].startY),
(float)(odabraniSegment[0].endX),
(float)(odabraniSegment[0].endY));
rect2 = maliOkvir.GetBounds();
G.DrawRectangle(pen5, rect2);
I'm getting an error on rect2
part:
G.DrawRectangles(pen5, rect2);
Cannot convert from 'System.Drawing.RectangleF' to 'System.Drawing.RectangleF[]'
How can I fix this? tried multiple variations of Rectangle
and RectangleF
, none works together.. the end result should look like this:
Upvotes: 0
Views: 2100
Reputation: 3180
You're using the DrawRectangles()
method of System.Drawing.Graphics
, which expects an array of Rectangle
s.
Use the singular version: DrawRectangle()
:
G.DrawRectangle(pen5, rect2.Left, rect2.Top, rect2.Width, rect2.Height); // Singular
MSDN gives you (a lot) of information about the Graphics
class.
Hope this helps!
Upvotes: 2
Reputation: 119076
The DrawRectangles
method expects an array of Rectangle
or RectangleF
objects but you are only passing in a single item. You should either:
DrawRectangle
Pass in an array:
G.DrawRectangles(pen5, new [] { rect2 });
Upvotes: 2