寻找矩形/表格的中心点 [英] Finding the centre point of a Rectangle/Form
本文介绍了寻找矩形/表格的中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试查找表单的中心点以进行定位
I''m trying to find the centre point of a form for positioning purposes
public class MyForm
{
public MyForm()
{
InitializeComponent();
Rectangle formRect = new Rectangle(Location, Size);
// want to find the centre point of formRect
// hoped there would be something like this
// Point centreOfform = formRect.CentrePoint();
}
}
我敢肯定有一个简单的方法可以做到这一点,但是目前,任何想法都在掩盖我.
I''m sure there is an easy way to do this but it is eluding me at the moment, any ideas.
Suppose I could divide the width by 2 and add it to x and the height by 2 and add it to y.
推荐答案
尊重全监视器扫描->
点p = new Point();
p.X =位置X +尺寸宽度/2;
p.Y =位置Y +尺寸高度/2;
仅尊重形式->
点p = new Point();
p.X = Size.Width/2;
p.Y =尺寸高度/2;
当您更改表单位置时,第一个将被更改,而第二个将被固定,它将保持不变.
Respect to Full monitor scan ->
Point p = new Point();
p.X = Location.X + Size.Width / 2;
p.Y = Location.Y + Size.Height / 2;
Only respect to form ->
Point p = new Point();
p.X = Size.Width / 2;
p.Y = Size.Height / 2;
when you change the form position then 1st one will be changed but the 2nd is fixed, it will not be changed.
这篇关于寻找矩形/表格的中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文