Imports System.Runtime.InteropServices Public Class Form1 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 <MarshalAs(UnmanagedType.Bool)> Boolean 'hdc '/* 塗りつぶしを行うデバイスハンドル */ 'x '/* 塗りつぶしを行う開始座標(x) */ 'y '/* 塗りつぶしを行う開始座標(y) */ 'crColor '/* 塗りつぶしを行う対象色 or 境界線色 */ 'wFillType '/* 塗りつぶしモードフラグ */ '/* 塗りつぶしモードフラグ */ Public Const FLOODFILLBORDER As UInteger = 0UI '/* crColorの色の境界線色まで塗りつぶしなさいモード */ Public Const FLOODFILLSURFACE As UInteger = 1UI '/* crColorの色の部分を塗りつぶしなさいモード */ Private Declare Function CreateBrushIndirect Lib "gdi32" _ (ByVal lpLogBrush As LOGBRUSH) As <MarshalAs(UnmanagedType.Bool)> Boolean Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As IntPtr, _ ByVal hObject As Integer) As <MarshalAs(UnmanagedType.Bool)> Boolean Private Structure LOGBRUSH Public lbStyle As Integer Public lbColor As Integer Public lbHatch As Integer End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim g As Graphics = Me.CreateGraphics Dim hdc As IntPtr = Me.Handle Dim x As Integer = 150 Dim y As Integer = 150 Dim crcolor As Integer = ColorTranslator.ToWin32(Me.BackColor) Dim wFillType As UInteger = FLOODFILLSURFACE Dim hNewBrush As Integer Dim hOldBrush As Integer Dim NewBrush As LOGBRUSH g.Clear(Me.BackColor) g.DrawRectangle(Pens.Red, 100, 100, 100, 100) 'ブラシの作成 NewBrush.lbColor = ColorTranslator.ToWin32(Color.Blue) NewBrush.lbStyle = 0 NewBrush.lbHatch = 5 hNewBrush = CreateBrushIndirect(NewBrush) 'ここでエラー 'ブラシを持ち替える hOldBrush = SelectObject(hdc, hNewBrush) ExtFloodFill(hdc, x, y, crcolor, wFillType) End Sub End Class