vb.netvisual-styles

VB.NET VisualStyleRenderer not working at all


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

Solution

  • 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.