# AutoRefresh (VB.NET)



## tim8w (Nov 9, 2004)

I have a function that needs to be called anytime the form is re-sized, minimized or maximized. In VB6, I could just set the AutoRefresh and call the function in the resize routine and everything worked fine. It doesn't seem to work that way in VB.NET. Any ideas?

Thanks,
Tim


----------



## tim8w (Nov 9, 2004)

A user, Craig Gemmill, on another forum solved it this way. It's pretty slick:


```
Private Sub frmJournal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.ResizeRedraw, True)
        Me.UpdateStyles()
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Using gradientBrush As New Drawing2D.LinearGradientBrush(Me.ClientRectangle, Color.Black, Color.Blue, Drawing2D.LinearGradientMode.Vertical)
            e.Graphics.FillRectangle(gradientBrush, Me.ClientRectangle)
        End Using
    End Sub
```


----------

