2016-05-03 35 views

回答

2

LineShape公開其座標與X1,X2,Y1Y2。發現它的中心是基本幾何形狀:

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 
+1

最後一步是將標籤的'Location.X'和'Location.Y'設置爲x'的'價值觀和'y'是@ Xiaoy312提到以上。 –

+1

@Sylverac實際上,它不會將標籤居中在線上,而是將標籤的左上角居中在線上。 – Xiaoy312

+0

啊,是的,我忘記了位置的起源在左上角。 –

相關問題