如何知道 LineShape 的中间
How to know the middle of a LineShape
我的表单中有一个 LineShape
,我需要在单击时标签正好出现在该行的中间,我应该用什么数学来确定这个中间点?
LineShape
将其坐标公开为 X1
、X2
、Y1
和 Y2
。找它的中心是基础几何:
LineShape line = /*...*/;
Label label = /*..*/;
// calculate the center of the line
var center = new Point((line.X1 + line.X2) / 2, (line.Y1 + line.Y2) / 2);
// center the label on the line
label.Top = center.Y - label.Height / 2
label.Left = center.X - label.Width / 2
我的表单中有一个 LineShape
,我需要在单击时标签正好出现在该行的中间,我应该用什么数学来确定这个中间点?
LineShape
将其坐标公开为 X1
、X2
、Y1
和 Y2
。找它的中心是基础几何:
LineShape line = /*...*/;
Label label = /*..*/;
// calculate the center of the line
var center = new Point((line.X1 + line.X2) / 2, (line.Y1 + line.Y2) / 2);
// center the label on the line
label.Top = center.Y - label.Height / 2
label.Left = center.X - label.Width / 2