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

Advertisements

About kishor datta gupta

Graduate Research Assistant at University of Memphis Software Engineer at Silicon Orchard LTD. Former Research Assistant at Lamar University Former Software Engineer at Samsung R&D Institute Bangladesh Studies Ph.D. Computer Science at University of Memphis Studied Masters of Science in Computer Sciences at Lamar University Studied BSC in CSE at Khulna University of Engineering and Technology Studied HSC (completed) at Chittagang college 04-06 Studied High school at ST. Placid's High School'04 Studied Junior Secondary School at Saint Mary's School Lives in Memphis, Tennessee
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