Option Strict On Public Class form1 '_____________________________VisualBasic2005以上 Private f As Boolean Private Px, Py As Integer Private g As Graphics Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load f = False g = Me.CreateGraphics() End Sub Private Sub form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If f = False Then Px = e.X Py = e.Y g.DrawRectangle(Pens.Red, Px, Py, 1, 1) Me.Text = ("終点をクリックしてください") f = True Else g.DrawRectangle(Pens.Red, e.X, e.Y, 1, 1) g.DrawLine(Pens.Black, Px, Py, e.X, e.Y) Me.Text = "始点をクリックしてください" f = False End If End Sub End Class