I have this code which draws a rectangle on a panel. It works great.
but it only lets me draw one. I want to be able to draw a lot of them and also save each of their coordinates, and then be able to recreate them. Yes this is a baby drawing program.
DougP
but it only lets me draw one. I want to be able to draw a lot of them and also save each of their coordinates, and then be able to recreate them. Yes this is a baby drawing program.
Code:
Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
Rect.Location = e.Location
End Sub
Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
Panel1.Cursor = Cursors.Cross
If e.Button = MouseButtons.Left Then
Rect.Size = New Size(e.X - Rect.X, e.Y - Rect.Y)
Panel1.Invalidate()
End If
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim L, T, W, H As Integer
L = Rect.X : T = Rect.Y
W = Rect.Width : H = Rect.Height
If W < 0 Then
L += W : W = -W
End If
If H < 0 Then
T += H : H = -H
End If
e.Graphics.DrawRectangle(Pens.Red, New Rectangle(L, T, W, H))
End Sub
DougP