我试图在VB(学校)的图片框中绘制两个矩形,但它似乎根本不起作用
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
答案 0 :(得分:1)
如果你没有在Paint事件中绘画,它将不会持续存在。
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