Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Paint Fill

Posted on 1998-08-27
Medium Priority
Last Modified: 2010-04-30
I would like to know how to get the screen to fill or be painted with respect to lines as boundries. Like the paint bucket in MSPaint.
Question by:bradsoblesky
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Accepted Solution

clifABB earned 80 total points
ID: 1431529
The following subroutine will flood from the X-Y point you pass it in the color you pass it:

Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long

Private Sub FillArea(X As Long, Y As Long, lColor As Long)
  Dim lOldColor As Long
  Dim lFillType As Long
  Dim lRes      As Long
  Const FLOODFILLBORDER = 0  ' Fill until crColor& color encountered.
  Const FLOODFILLSURFACE = 1 ' Fill surface until crColor& color not
                             ' encountered.
  Picture1.FillColor = lColor
  lOldColor = Picture1.Point(X, Y)
  lRes = ExtFloodFill(Picture1.hdc, X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY, lOldColor, lFillType)
End Sub


Author Comment

ID: 1431530
Where do I put each of these? So I click on the picture or form and it does it.

Expert Comment

ID: 1431531
I would suggest the MouseUp event of the picture control:

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbLeftButton Then
    'lColor is set elsewhere
    FillArea X, Y, lColor
  End If
End Sub

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1431532
This is not working for me it tells me that lcolor is not defined and something about the part of the sub int "()" is not valid. Help.  


Expert Comment

ID: 1431533
You need to define lColor either globally or at module level and assign it a value (it would default to 0 which is black)

In the FillArea procedure, add the following line just before the FillColor line:
  Picture1.FillStyle = vbFSSolid
Finally, in the MouseUp routine, make this small change to the Call to FillArea():
    FillArea CLng(X), CLng(Y), lColor


Author Comment

ID: 1431534
Sorry about all the trouble. Thanks.

Expert Comment

ID: 1431535
No problem.  Glad I could help.  :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question