2013-12-23 24 views
0

我需要一個聰明的算法來檢測哪個邊被點擊,而不是查看圖中的每個邊。檢測點擊其他重疊子控件隱藏的子控件

enter image description here

,你可以在上圖中,用點來標記的區域表示點擊邊緣看到不正確的,因爲它們是由邊緣重疊[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)); 
    } 

我怎麼能遍歷所有子窗口/控件在某些點?

回答

0

我能想到的唯一的事情就是通過你的窗體的控件集合進行迭代,並檢查每個控件的邊界包含你的觀點。

這可能是也可能不是你取決於你有控制的數量是可行的。

foreach (Control c in this.Controls) 
{ 
    if (c.Bounds.Contains(mpc)) 
    { 
     //process the match here 
    } 
} 
相關問題