0
我需要一個聰明的算法來檢測哪個邊被點擊,而不是查看圖中的每個邊。檢測點擊其他重疊子控件隱藏的子控件
,你可以在上圖中,用點來標記的區域表示點擊邊緣看到不正確的,因爲它們是由邊緣重疊[2-> 3]
我試圖GetChildAtPoint但它返回只有最上面的孩子。
class Edge : Control {
public Movable From {get;set;}
public Movable To {get;set;}
...}
void Edge_Click(object sender, EventArgs e)
{
var clicked = (Edge)sender;
var mpc = this.PointToClient(MousePosition);
var clk0 = this.GetChildAtPoint(mpc) as Edge;
Edge clk = null;
if (clk0 != null) {
if (clk0.GetType() == typeof(Edge))
clk = clk0 as Edge;
}
MessageBox.Show(string.Format("({0}, {1}): {2} - {3}=>{4} - {5}: {6}",
mpc.X, mpc.Y, clicked.Parent.GetType().ToString(),
clicked.From.Text, clicked.To.Text,
(clicked == clk).ToString(),
clk == null ? "null" : clk.From.Text + "=>" + clk.To.Text));
}
我怎麼能遍歷所有子窗口/控件在某些點?