I have this code:
Sub drawborder()
Dim objGraphics As Graphics
objGraphics = Me.CreateGraphics
objGraphics.Clear(System.Drawing.SystemColors.Control)
objGraphics.DrawRectangle(System.Drawing.Pens.Red, picShowPicture.Left - 1, picShowPicture.Top - 1, picShowPicture.Width + 1, picShowPicture.Height + 1)
objGraphics.Dispose()
borderstatus.Text = "Border Drawn"
End Sub
and this draws a border around a PictureBox. Now I want to use another button to remove it again but I can’t seem to make it work.
Don’t use
CreateGraphics, that’s just a temporary drawing that will be erased when you minimize the form or move it off screen, etc.Try holding a variable and then just invalidate the form: