Linear gradient background does not repaint correctly.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bryon

    #1

    Linear gradient background does not repaint correctly.

    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(B yVal sender As Object, ByVal e As
    System.Windows. Forms.PaintEven tArgs) Handles Me.Paint

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

    'declare brushes for linear gradient.
    Dim brushTop As New LinearGradientB rush(rectTop, Color.SlateGray ,
    Color.Transpare nt, LinearGradientM ode.Vertical)
    Dim brushBottom As New LinearGradientB rush(rectBottom ,
    Color.Transpare nt, Color.DarkGray, LinearGradientM ode.Vertical)

    'paint areas with gradients upon form refreshes and repaints
    e.Graphics.Fill Rectangle(brush Top, rectTop)
    e.Graphics.Fill Rectangle(brush Bottom, rectBottom)

    brushTop.Dispos e()
    brushBottom.Dis pose()

    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.

  • Armin Zingler

    #2
    Re: Linear gradient background does not repaint correctly.

    "Bryon" <residualfear@g mail.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(Con trolStyles.Resi zeRedraw, True)

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


    Armin

    Comment

    Working...