我有一个带有平面图图像的 PictureBox。
在该图像上,我想绘制一个多边形,我可以使用以下代码:
Private points As New List(Of Point)
Private Sub FlorPlan_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FlorPlan.MouseDown
points.Add(e.Location)
FlorPlan.Invalidate(New Rectangle(e.X, e.Y, 5, 5))
End Sub
Private Sub FlorPlan_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles FlorPlan.Paint
For Each p As Point In points
e.Graphics.FillRectangle(Brushes.Red, p.X, p.Y, 5, 5)
Next
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myPen As Pen
myPen = New Pen(Drawing.Color.Red, 2)
Dim myGraphics As Graphics = PictureBox.CreateGraphics
myGraphics.DrawPolygon(myPen, points.ToArray)
'myGraphics.FillPolygon(Brushes.Red, points.ToArray)
myGraphics.Dispose()
End Sub
我想做的是抓住那个对象,这样我以后就可以改变背景颜色等。
我应该如何进行?