質問
hWndが子コントロールのいずれかに属しているかどうかを確認するにはどうすればよいですか?
次のようなことをしたい:
if(this.Controls.Find(hWnd) != null) return false;
解決
このためのWin32関数があります。 IsChild
他のヒント
再帰を使用する絶好の機会のようです。この関数を親クラスに追加します。
private bool IsChild(System.Windows.Forms.Control control, System.IntPtr hWnd)
{
if(control.Handle == hWnd)
return(true);
foreach (System.Windows.Forms.Control child in control.Controls)
{
if (IsChild(child, hWnd))
return (true);
}
return (false);
}
この関数を使用して、指定されたhWndを持つ子コントロールをこの親クラスで検索できます:
this.IsChild(this, hWnd);
所属していません StackOverflow