How to use RectangleConverter?

I am constantly converting rectangles back and forth from int based to float based rectangle.

I have noticed the RectangleConverter class, but there are no samples (that I can find).

Does anyone have any experience with this class

Right now I am constantly writing this code to convert from a RectF to a Rect

Rectangle r = new Rectangle((int)rF.X, (int)rF.Y, (int)rF.Width. (int)rF.Height);

And it is a big pain! I have even written a class that creates 2 rectangle objects and keeps them in sync. But there must be a better way.

Any help would be much appreciated!

Thanks,

Bob



Answer this question

How to use RectangleConverter?

  • myGreenBird

    The RectangleConverter class is used to convert string repretations to a Rectangle and versa vista. What you need is the Rectangle.Round method, this converts the specified RectangleF to a Rectangle by rounding the RectangleF values to the nearest integer values.


    RectangleF myRectF = new RectangleF(150f, 150f, 150f, 150f);
    Rectangle myRect = Rectangle.Round(myRectF);



  • How to use RectangleConverter?