0
我的表格中有一個LineShape
,我需要點擊一個標籤時恰好出現在這一行的中間,我應該怎麼做才能確定這個中間點?如何知道一個LineShape的中間點
我的表格中有一個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
最後一步是將標籤的'Location.X'和'Location.Y'設置爲x'的'價值觀和'y'是@ Xiaoy312提到以上。 –
@Sylverac實際上,它不會將標籤居中在線上,而是將標籤的左上角居中在線上。 – Xiaoy312
啊,是的,我忘記了位置的起源在左上角。 –