Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load PictureBox1.Refresh() PictureBox2.Refresh() PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) PictureBox2.Image = New Bitmap(PictureBox2.Width, PictureBox2.Height) Me.Width = 510 : Me.Height = 500 PictureBox1.Width = 350 : PictureBox1.Height = 300 PictureBox2.Width = 350 : PictureBox2.Height = 300 PictureBox1.BorderStyle = BorderStyle.FixedSingle PictureBox2.Visible = False Label1.Text = "マウス左ボタン 自由ライン作図" Label2.Text = "塗りつぶし マウス右ボタンで" Label2.ForeColor = Color.Brown Button1.Text = "画面を最初に戻す" PictureBox1.Refresh() PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) Dim gr As Graphics = Graphics.FromImage(PictureBox1.Image) ' PictureBox1.CreateGraphics gr.DrawRectangle(Pens.Red, 20, 20, 100, 100) gr.DrawRectangle(Pens.Green, 40, 60, 120, 100) gr.DrawRectangle(Pens.Black, 50, 100, 120, 100) gr.DrawRectangle(Pens.Blue, 60, 140, 120, 100) gr.FillRectangle(Brushes.Red, 180, 20, 120, 100) gr.FillRectangle(Brushes.Blue, 200, 40, 120, 100) End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) End Sub Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs) Handles PictureBox1.Click End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove '---- 自由ラインを描く ---- 閉じた図形とすること If e.Button = System.Windows.Forms.MouseButtons.Left Then PictureBox1.Refresh() Dim g As Graphics = Graphics.FromImage(PictureBox1.Image) Dim myPen As New Pen(Color.Green, 3) g.DrawLine(myPen, oldX, oldY, e.X, e.Y) PictureBox1.Image = PictureBox1.Image g.Dispose() 'Invalidate() End If oldX = e.X : oldY = e.Y End Sub