Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFill an irregular area with the FloodFill API function
Keywordsflood, floodfill
CategoriesGraphics
 
Create and select a brush using the color you want. Use the FloodFill API function to fill the area.
 
Private Sub Form_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim color As Long
Dim brush As Long
Dim old_brush As Long

    ' Pick a random color other than black and
    ' the point's current color.
    Do
        color = QBColor(Int(15 * Rnd + 1))
    Loop While color = Point(X, Y)

    ' Create and select a brush of this color.
    brush = CreateSolidBrush(color)
    old_brush = SelectObject(hdc, brush)

    ' Do the flood,stopping when we
    ' reach black pixels.
    FloodFill hdc, X, Y, vbBlack

    ' Select the old brush and delete the new one.
    brush = SelectObject(hdc, old_brush)
    DeleteObject brush

    Refresh
End Sub
 
My book Visual Basic Graphics Programming has much more information about using API functions to draw graphics.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated