Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown If e.Button = System.Windows.Forms.MouseButtons.Right Then Dim g As Graphics = Graphics.FromImage(PictureBox1.Image) Dim hWnd As IntPtr = PictureBox1.Handle Dim hdc As IntPtr = GetWindowDC(hWnd) Dim wFillType As UInteger = 1 ' FLOODFILLSURFACE Dim hNewBrush As IntPtr Dim hOldBrush As IntPtr Dim NewBrush As LOGBRUSH NewBrush.lbColor = ColorTranslator.ToWin32(Color.Yellow) NewBrush.lbStyle = 0 NewBrush.lbHatch = 0 hNewBrush = CreateBrushIndirect(NewBrush) hOldBrush = SelectObject(hdc, hNewBrush) ExtFloodFill(hdc, e.X, e.Y, GetPixel(hdc, e.X, e.Y), wFillType) 'wFillType= FLOODFILLSURFACE=1 Dim gr As Graphics = Graphics.FromImage(PictureBox2.Image) Dim hDC2 = gr.GetHdc BitBlt(hDC2, 0 - 1, 0 - 1, 350, 300, hdc, 0, 0, SRCCOPY) 'SRCCOPY=&HCC0020& PictureBox1.Image = PictureBox2.Image ReleaseDC(hWnd, hdc) 'デバイスコンテキストを開放する hNewBrush = SelectObject(hdc, hOldBrush) '元のブラシに戻す DeleteObject(hNewBrush) '不要になったブラシを開放する g.Dispose() ReleaseDC(hWnd, hDC2) gr.Dispose() End If End Sub Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) Handles Button1.Click PictureBox1.Image = Nothing 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 End Class