Imports System.Runtime.InteropServices Public Class Form1 Private Const FLOODFILLBORDER As UInteger = 0 ' 境界色を目印にして塗りつぶすとき Private Const FLOODFILLSURFACE As UInteger = 1 ' 領域色を目印にして塗りつぶすとき(複数色の境界色で囲まれているときなど) Private Structure LOGBRUSH Public lbStyle As Integer Public lbColor As Integer Public lbHatch As Integer End Structure Private Declare Function CreateBrushIndirect Lib "gdi32" (ByRef lpLogBrush As LOGBRUSH) As IntPtr Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As IntPtr, ByVal hObject As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean Private Declare Function ExtFloodFill Lib "gdi32" _ (ByVal hdc As IntPtr, _ ByVal X As Integer, _ ByVal Y As Integer, _ ByVal crColor As Integer, _ ByVal wFillType As UInteger) As Boolean Private ClickPT As Point = New Point(-1, -1) Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click ClickPT = PictureBox1.PointToClient(Control.MousePosition) PictureBox1.Refresh() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint Dim g = e.Graphics For i = 0 To 5 g.FillRectangle(Brushes.Black, i * 35 + 5, 5, 30, 30) Next If ClickPT.X >= 0 AndAlso ClickPT.Y >= 0 Then Dim hdc = g.GetHdc Dim brs As New LOGBRUSH brs.lbColor = ColorTranslator.ToWin32(Color.Red) brs.lbHatch = 0 brs.lbStyle = 0 Dim hNewBrush = CreateBrushIndirect(brs) Dim hOldBrush = SelectObject(hdc, hNewBrush) ExtFloodFill(hdc, ClickPT.X, ClickPT.Y, 0, FLOODFILLSURFACE) g.ReleaseHdc() DeleteObject(hNewBrush) End If ClickPT = New Point(-1, -1) End Sub End Class