1
我的表單層次結構是這樣的:GetChildAtPoint方法返回錯誤的控制
Form -> TableLayoutOne -> TableLayoutTwo -> Panel -> ListBox
在ListBox的MouseMove事件,我有這樣的代碼:
Point cursosPosition2 = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y));
Control crp = this.GetChildAtPoint(cursosPosition2);
if (crp != null)
MessageBox.Show(crp.Name);
MessageBox的是顯示我是「TableLayoutOne」,但我期望它向我展示「ListBox」。我的代碼中哪裏出錯了?謝謝。
當然!感謝您的信息...你有其他想法如何得到它?也許閱讀Cursor位置並檢查它是否在ListBox的位置內? – Bohn
查看我的更新;您可以繼續在返回的控件上調用'GetChildAtPoint()'以在層次結構中進一步深入。你也可以在每個階段自由地檢查控制的類型,所以如果你找到了你想要的東西,你就可以紓困。 – dlev