Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How might I convert a Rectangle to a RectangleF?

What is the easiest way to convert a Rectangle to a RectangleF in .NET?

Edit: This sounds trivial and it is, but I was trying to save some typing. The best I could come up with:

RectangleF rdest(rsrc.Location, rsrc.Size); // C++/CLI

...or...

RectangleF rdest = new RectangleF(rsrc.Location, rsrc.Size) // C#
like image 882
Agnel Kurian Avatar asked Aug 27 '09 05:08

Agnel Kurian


1 Answers

There's an implicit converter, so you can simply do:

RectangleF rectanglef = rectangle;

http://msdn.microsoft.com/en-us/library/system.drawing.rectanglef.op_implicit.aspx

In fact, you already knew that: it's easily missed, but your code is using two such implicit casts - you're using Point and Size where there should be PointF and SizeF.

like image 133
Kobi Avatar answered Nov 12 '22 19:11

Kobi