VB.NET VisualStyleRenderer not working at all

191 views Asked by At

Does anybody see my mistake here?

Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
    Dim renderer As VisualStyleRenderer
    renderer = New VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)

    Dim nRect As New Rectangle
    nRect = Rectangle.FromLTRB(0, 0, 100, 100)

    renderer.DrawBackground(Me.PictureBox1.CreateGraphics, nRect)
    Me.PictureBox1.Invalidate(True)
End Sub
1

There are 1 answers

1
SLaks On BEST ANSWER

You should never draw on CreateGraphics(); it will be erased next time the control paints itself.

Instead, you need to handle the Paint event and draw on e.Graphics.