Reputation: 1
I am trying to draw two rectangles in a picture box in VB (for school) but it does not seem to work at all
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim paper As Graphics()
paper = PictureBox1.CreateGraphics()
Dim pen As Pen = New Pen(Color.Black)
paper.DrawRectangle(pen, 10, 10, 100, 50)
paper.DrawRectangle(pen, 10, 75, 100, 100)
End Sub
Upvotes: 0
Views: 6255
Reputation: 9024
If you don't paint in the Paint event it will not persist.
Private Sub Picturebox1_Paint(ByVal sender As Object, ByVal e As System.PaintEventArgs) Handles Picturebox1.Paint
Using pen As New Pen(Color.Black)
e.Graphics.DrawRectangle(pen, 10, 10, 100, 50)
e.Graphics.DrawRectangle(pen, 10, 75, 100, 100)
End Using
End Sub
Upvotes: 1