Click here to Skip to main content
14,357,121 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to search control location ( x , y ) in MDI child form . How to search it ???

What I have tried:

can find location in mdi parent
Posted
Updated 30-Nov-16 21:00pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Recursively follow the Controls collection, looking at each items Location:
Control findLoc(ControlCollection controls, Point loc)
   {
   if (controls != null)
      {
      foreach (Control c in controls)
         {
         if (c.Location == loc)
            {
            return c;
            }
         Control f = findLoc(c.Controls, loc);
         if (f != null) return f;
         }
      }
   return null;
   }
Do note that the Location property is relative to the container, not the screen - so you may need to alter the target loc to allow for that when you recurse into it's Controls collection.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100