By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Linear gradient background does not repaint correctly.

P: n/a
My current code paints a rectangular area at the top (under the menu and
tool strip) and bottom (top of the status strip) of the main form with a
linear gradient. The problem is that when the form is resized or maximized
for that matter, the form still displays the last areas that were painted
with gradient. Basically the form does not erase the last graphics that
were painted to the form and just paints over it with the new. My code is
as follows in the form paint event.

----------------------

Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

'declare rectangle dimensions for areas to be painted. Areas will be 64
pixels high.
Dim rectTop As New Rectangle(0, (mainMenu.Height + tsSearchBar.Height),
Me.Width, 64)
Dim rectBottom As New Rectangle(0, (Me.Height - (64 +
ssMessages.Height)), Me.Width, 64)

'declare brushes for linear gradient.
Dim brushTop As New LinearGradientBrush(rectTop, Color.SlateGray,
Color.Transparent, LinearGradientMode.Vertical)
Dim brushBottom As New LinearGradientBrush(rectBottom,
Color.Transparent, Color.DarkGray, LinearGradientMode.Vertical)

'paint areas with gradients upon form refreshes and repaints
e.Graphics.FillRectangle(brushTop, rectTop)
e.Graphics.FillRectangle(brushBottom, rectBottom)

brushTop.Dispose()
brushBottom.Dispose()

End Sub

----------------------

If anyone can help me solve why this is happening, I'd be much appreciative.
I'm pretty sure that the problem is something simple that I just can't see.
Thanks in advanced.

Mar 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Bryon" <re**********@gmail.comschrieb
My current code paints a rectangular area at the top (under the menu
and tool strip) and bottom (top of the status strip) of the main
form with a linear gradient. The problem is that when the form is
resized or maximized for that matter, the form still displays the
last areas that were painted with gradient. Basically the form does
not erase the last graphics that were painted to the form and just
paints over it with the new. My code is as follows in the form
paint event.
[...]
Only revealed areas are repainted. Try

Me.SetStyle(ControlStyles.ResizeRedraw, True)

in the Form's constructor. Anywhere else, additionally call
Me.Updatestyles.
Armin

Mar 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.