Painting Background - No Resizing Well

P

Phil Jones

I'm painting a gradient onto a control by overrideing the
"OnPaintBackground" method like so:


Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
Dim brush As New LinearGradientBrush( _
New Point(0, 0), _
New Point(ClientSize.Width, 0), _
Color.Red, _
Color.Orange)
Dim size As New Rectangle(0, 0, Me.Width, Me.Height)
e.Graphics.FillRectangle(brush, size)
End Sub


The problem is that when I resize the control, parts of the graident don't
redraw correctly (patchy squares emerge). Am I missing something here with
how you're supposed to paint things? I'm setting the fill area to the size
of the control - what should I be doing???

Many thanks!

===
Phil
(Auckland | Aotearoa)
 
C

ClayB [Syncfusion]

Try adding this code to your control's constructor.

SetStyle(ControlStyles.ResizeRedraw, true)

It forces the control to entirely redraw itself when you resize. Without
this setting, only the newly exposed parts of the control are invalidated,
and I think this is what is causing the patchy look.

=====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
P

Phil Jones

Woooo! Like it when it's that easy!

Thanks Clay - I would never have found that by myself (it's doesn't even
come up on the intellisense list).

===
Phil
(Auckland | Aotearoa)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top