Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

AreaFill - Fill an area with a solid color

Total Hit ( 3880)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Private Declare Function ExtFloodFill Lib "GDI32" (ByVal hDC As Long, _
  ByVal X As Long, ByVal Y As Long, ByVal colorCode As Long, _
  ByVal fillType As Long) As Long
Const FLOODFILLBORDER = 0
Const FLOODFILLSURFACE = 1

' Fill a region using the current color or brush
'  OBJ can be a form or a control that exposes
'    a device context (eg a picture box)
'  X,Y are given in the current system coordinates
'
' If BORDERCOLOR is specified, fills the area
'  enclosed by a border of that color
' If BORDERCOLOR is omitted, the area is filled with
'  the color now at coordinates (x,y), and any
'  different color is considered to a the border

Sub AreaFill(obj As Object, ByVal X As Long, ByVal Y As Long, _
  ByVal colorCode As Long, Optional borderColor As Variant)
  
  Dim x2 As Long, y2 As Long
  Dim saveFillStyle As Long
  Dim saveFillColor As Long
  
  With obj
    ' convert into pixel coordinates
    x2 = .ScaleX(X, .ScaleMode, vbPixels)
    y2 = .ScaleY(Y, .ScaleMode, vbPixels)
    
    ' save FillStyle and FillColor properties
    saveFillStyle = .FillStyle
    saveFillColor = .FillColor
    ' enforce new properties
    .FillStyle = 0
    .FillColor = colorCode
    
    If IsMissing(borderColor) Then
      ' get color at given coordinates
      borderColor = .Point(X, Y)
      ' change all the pixels with that color
      ExtFloodFill .hDC, x2, y2, borderColor, FLOODFILLSURFACE
    Else
      ExtFloodFill .hDC, x2, y2, borderColor, FLOODFILLBORDER
    End If

    ' restore properties
    .FillStyle = saveFillStyle
    .FillColor = saveFillColor
  End With

End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.