Vu que tu utilises l'event _Paint,
pas besoin de faire un DrawRectangle dans ton Button2_Click
de plus, n'utilises pas :
Me.PictureBox1.CreateGraphic
utilises celui qui t'es fournit en parametre:
e.Graphics
au final, j'ai placé trois checkBoxes qui permettent d'afficher/masquer un rectangle :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.ImageLocation = "C:\...\...jpg"
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If CheckBox1.Checked Then
e.Graphics.DrawRectangle(Pens.Red, 0, 0, 20, 20)
End If
If CheckBox2.Checked Then
e.Graphics.DrawRectangle(Pens.Green, 40, 0, 20, 20)
End If
If CheckBox3.Checked Then
e.Graphics.DrawRectangle(Pens.Blue, 80, 0, 20, 20)
End If
End Sub
Private Sub CheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged
PictureBox1.Invalidate()
End Sub
Renfield - Admin CodeS-SourceS - MVP Visual Basic