10

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#

1 Answer 1

21

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The OP implicitly knows it ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.