VB.NET VisualStyleRenderer not working at all
-
13-07-2021 - |
Question
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
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow