previously, there is such method for Rectangle in MFC, i dont know why there is not for the c# version.
Presumably it wasn't deemed useful enough to merit inclusion.
You could easily add it as an extension method if you want though (and if you're using C# 3):
public static Point Center(this Rectangle rect)
{
return new Point(rect.Left + rect.Width/2,
rect.Top + rect.Height / 2);
}
Note that as the values are expressed as integers, you could easily end up getting a non-exact value, assuming you want to return a Point
rather than another structure using decimal
or double
.
The above is actually for the System.Drawing.Rectangle
struct. If you're talking about a different Rectangle, please add the appropriate information and I'll edit my answer.
It exists within the (no longer supported) Microsoft.XNA.Framework.
Rectangle.Center Property
myRectangle.Center
returns a Point
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With