Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to know center of rectangle?
Posted
Comments
_Asif_ 15-Jan-15 2:54am    
What have you tried so far? This is not a good way in asking questions

If you have had given a try by googling center of rectangle C#, you probably got answer yourself without asking any one. But it seems that new generation developers don't even want to do a simple search. Anway!

Check this article

Extension methods for finding centers of a rectangle[^]
 
Share this answer
 
Independently from the programming language, that's simple math: the center of the rectangle is halfway its top-left and bottom-right points

xc = (xtl + xbr) / 2; 
yc = (xtl + xbr) / 2; 


or if you have the rectangle width and heigh,
xc = xtl + w / 2;
yc = ytl + h / 2;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900