OnPaintBackground vs. Scrollbar

  • Thread starter Thread starter Lelekács Zoltán
  • Start date Start date
L

Lelekács Zoltán

Hi,

I have a user painted backgrounf form.
When form has got a scrollbar I run into trouble with drawing.

I get the ClipRectangle in the EventArgs. It is depends on the graphics
face, not the virtual (I mean that if I have a from with 400px of height and
have a control at 600px and I scroll to the control I will get a
ClipRectangle with Y like 25px, not 575px with 200px height).

Even I cannot ask the virtual clientsize of the form, only the displayable
face through Form.ClientSize. There is a PrefferedSize property, but it
gives the form.Height value, not the ClientHeight... So I have determine the
"border" of the form...
But even complicated with scrollbar...

So the real question is:
Do I miss something or missunderstood with OnBackground paint +
ClipRectangle + Scrollbar.Value and Scrollbar.Maximum (which does NOT gives
the PrefferedSize.Height if it is the VScrolllbar.Maximum property)?
Or what is the nice solution to handle the scrollbar value and draws the
exact face of the background (if the face of the background as big as the
virtual size of the form)?

Thanks.

lelez
 
The clip rectangle reflects the amount of pixels that the window has moved.
The underlying ScrollWindow API will have already shifted the bits of the
current window and you'll be required to draw just the bit that needs a
refresh.

You can ignore the clip rectangle and just go ahead and draw the whole thing
but the clever way is to check the clip size and only draw what's needed.
Remember that the scroll bars will cause an offset in the window origin that
you'll need to compensate for with a suitable transform.

See the article in Windows Forms Tips and Tricks about understanding
autoscroll.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top