Let's say I have a custom
You can use this code:
var c = textBox1; var p1 = c.Parent.PointToScreen(c.Location); var p2 = this.PointToScreen(new Point(0, 0)); var p = new Point(p1.X - p2.X, p1.Y - p2.Y); var bounds = new Rectangle(p, c.Size);
I suppose this code is executing in
bounds is what you are looking for.
In above code
p1 is screen location of
p2 is screen location of the first point of top container (
UserControl1). So the difference between these points is the relative location of
textBox1. Then since the size is not relative then bounds would be
new Rectangle(p, c.Size);.
The code will work with any hierarchy regardless of depth.