Visible != You can see it
The Visible
property on Controls is a bit misleading. Aside from the fact that setting it to true, is really only an advisory setting, since it's truth is also dependent on all its parents, there is the issue that is has nothing to do with whether it's actually visible when the form is painted.
Simple example: You have a Control
A in a panel and that panel is half off-screen (or at least half across the edge of its container. And A is in the part of the panel that's obscured. A is going to be Visible
, even though its not visible.
The interesting thing is that the paint cycle knows this, and OnPaint
won't be called on the Control
. Now wouldn't it be nice if there was a property that told you that your Visible
control won't be drawn? If there is a simple way to determine this, I haven't found it (especially not on .NETCF 1.0).
The way I do it now is that i use RectangleToScreen
on the Control
and then recursively walk up the parents, get their screen rectangle and call IntersectsWith
on the control's Rectangle and each Parent
. As soon as i find one that doesn't intersect, I know the Control is not going to be drawn.