На форму необходимо поместить PictureBox и переименовать его в pctMain Option Strict On Option Explicit On Public Class MainForm Dim p(1), pe(1) As Point Dim myArray As ArrayList = New ArrayList() Private Sub pctMain_MouseDown(ByValsender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pctMain.MouseDown p(0) = e.Location myArray.Add(p(0)) End Sub Private Sub pctMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pctMain.MouseMove If myArray.Count = 0 Then Return p(1) = e.Location pctMain.Invalidate() End Sub Private Sub pctMain_Paint(ByVal sender As Object, ByVale As System.Windows.Forms.PaintEventArgs) Handles pctMain.Paint Dim i As Integer For i = 1 To myArray.Count - 1 Step 1 pe(0) = CType(myArray.Item(i - 1), Point) pe(1) = CType(myArray.Item(i), Point) e.Graphics.DrawLine(Pens.Blue, pe(0).X, pe(0).Y, pe(1).X, _ pe(1).Y) Next i e.Graphics.DrawLine(Pens.Blue, p(0).X, p(0).Y, p(1).X, p(1).Y) End Sub End Class
|