This is my son?

How can I tell if hWnd belongs to one of my child controls?

I want to do something like:

if(this.Controls.Find(hWnd) != null) return false;

      

+1


a source to share


2 answers


There is a Win32 function here: IsChild



+3


a source


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);
  }

      



Then you can use this function to find this parent class for any child controls with the specified hWnd:

this.IsChild(this, hWnd);

      

+2


a source







All Articles