Spooner
Spooner

Reputation: 31

Is the documentation wrong for Graphics.IsVisible(Rectangle rect)?

Microsoft's online documentation says that this Graphics method returns "true if the rectangle specified by the rect parameter is contained within the visible clip region of this Graphics; otherwise, false".

Do they really mean that? It would be much more useful to have it return true if any part of rect lies within the clip region. That way, if rect was the bounding rectangle of some object to be drawn, you would know if none of the object was on view and you could safely skip it.

I've experimented with some very simple WinForms code and the method does appear to behave as I'd like rather than as the documentation says. But I'm reluctant to assume I'm right. Does anyone know for sure?

And while I'm talking about the documentation for this, does anyone have a definition of "visible clip region"? Microsoft says it's "the intersection of the clipping region of this Graphics and the clipping region of the window", but there must be more to it than that: some Graphics objects, for example, don't even have a window (if they're associated with a Bitmap in memory).

Experimentation suggests that if, say, you're painting onto a rectangular Panel of size X by Y, the Graphics clip region is intersected with an X-by-Y rectangle. And apparently this continues to apply if the Panel is bigger than its containing Form and partly scrolled out of view. But again, it would be good to know what the actual rules are.

All accumulated wisdom is gratefully received.

Upvotes: 3

Views: 121

Answers (1)

EricSchaefer
EricSchaefer

Reputation: 26370

I don't know about the documentation, but my experience is pretty much aligned with your observation, that the method returns true, if any part of the rectangle is within the visible clip region of the Graphics.

Don't overthink this. Documentation is never as precise as code. Any sizable body of documentation will contain such imprecise definitions.

Upvotes: 2

Related Questions