You need to remember that the autoscroll function is providing you with a
window onto a virtual client area that is larger than the visible area of
the page. You have to compensate for this and the position of the scroll
bars in any painting you do.
I suspect that the area you want to fill is really the size of the
auto-scroll minimum sizes so you might do something like this to create the
brush...
dim cr as new Rectangle(0,0,me.AutoScrollMinSize.Width,
Me.AutoScrollMinSize.Height)
HB = New System.Drawing.Drawing2D.LinearGradientBrush(cr,
Color.White,Color.LightSteelBlue, Drawing2D.LinearGradientMode.Vertical)
Now you can compensate for the scroll positions
dim mx as new Matrix(1,0,0,me.AutoScrollPosition.X, me.AutoScrollPosition.Y)
e.Graphics.Transform=mx
e.Graphics.FillRectangle(HB,cr)
this can be used in the Paint or OnPaintBackground override.
--
Bob Powell [MVP]
Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm The GDI+ FAQ RSS feed:
http://www.bobpowell.net/faqfeed.xml Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tipstricks.xml Bob's Blog:
http://bobpowelldotnet.blogspot.com/atom.xml [quoted text, click to view] "news.microsoft.com" <Brian@dontspam.com> wrote in message
news:e0rurWCaEHA.3804@TK2MSFTNGP10.phx.gbl...
> I am painting a gradient background on a sizeable form. We are setting the
> autoscroll margins so that the form scrolls when needed. However, when
this
> is done, if the user clicks on the scroll bar and drags it, then the
> gradient doesn't paint correctly. Nothing I have tried seems to paint this
> newly exposed region correctly with proper blend of the gradient.
>
> Here is what I tried initially and is a good example of it not painting
> properly when scrolled:
>
> Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
>
> Dim HB As System.Drawing.Drawing2D.LinearGradientBrush
>
> Dim r As Rectangle
>
> r = Me.ClientRectangle
>
> HB = New System.Drawing.Drawing2D.LinearGradientBrush(r, Color.White,
> Color.LightSteelBlue, Drawing2D.LinearGradientMode.Vertical)
>
> e.Graphics.FillRectangle(HB, r)
>
> HB.Dispose()
>
> End Sub
>
> Then I tried creating an image and retrieving the rectangle that
corresponds
> to the clipped region without succuss:
>
> Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
>
> Dim HB As System.Drawing.Drawing2D.LinearGradientBrush
>
> Dim r As Rectangle
>
> Dim img As Bitmap
>
> Dim g As Graphics
>
> r = Me.ClientRectangle
>
> img = New Bitmap(Me.Width, Me.Height)
>
> g = Graphics.FromImage(img)
>
> HB = New System.Drawing.Drawing2D.LinearGradientBrush(r, Color.White,
> Color.LightSteelBlue, Drawing2D.LinearGradientMode.Vertical)
>
> g.FillRectangle(HB, r)
>
> e.Graphics.DrawImage(img, e.ClipRectangle, e.ClipRectangle,
> GraphicsUnit.Pixel)
>
> g.Dispose()
>
> HB.Dispose()
>
> End Sub
>
> Does anyone see where I have gone wrong or have the solution that I am
> looking for?
>
> Thanks, Brian
>
>
>
>