DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Calculate Control's Absolute Screen Location
For example for control Label1:
this.PointToScreen(this.Label1.Location)






Comments
Snippets Manager replied on Thu, 2008/01/10 - 5:35am
private Point findCoords2(Control c) { // Recurse through all parent controls... Point coord = new Point(); // Own location inside control coord = c.Location; // Add parents control coord (There is always at least one parent! ... if this isn't the Form...) while (c.Parent != null) { c = c.Parent; coord.X += c.Location.X; coord.Y += c.Location.Y; } // Add pixel borders coord.X += c.Margin.Left + 1; // 23 for "classic" Windows look // 30 for Windows XP standard look //coord.Y += 30; // Or try this... coord.Y += c.Bounds.Height - c.ClientSize.Height - (c.Margin.Top + 1); return coord; }