How can I tell if an hWnd belongs to one of my child controls?
I want to do something like:
if(this.Controls.Find(hWnd) != null) return false;
How can I tell if an hWnd belongs to one of my child controls?
I want to do something like:
if(this.Controls.Find(hWnd) != null) return false;
Sounds like a great chance to use recursion. Add this function to your parent class:
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);
}
You can then use this function to search this parent class for any child controls with the specified hWnd:
this.IsChild(this, hWnd);