c# tips: findout the midpoint of rectangle

In c# Rectangle class takes 4 parameter start location x and y point and height and width. some time we may need the center point of rectangle.
for find out the mid point u can use this class

Point midp(Rectangle r)
Rectangle a = (Rectangle)r; //take the ractngle
int x = a.Location.X;
int y = a.Location.Y;
int h=a.Height;
int w = a.Width;
Point pp = new Point();
pp.X = Convert.ToInt32(x + w / 2); //calculate mid point x
pp.Y = Convert.ToInt32(y + h / 2); //cal culate mid point y
return pp

hope this tricks will helps


About kishordgupta

A software developer
This entry was posted in C#, Image Processing and tagged , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s