Make your own free website on Tripod.com

Paint Saparate Areas Of Picture

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'This example will show you how to paint separated parts picture by clicking on it,
'Like painting book.
'Add 1 PictureBox (named Picture1) to your form.
'Insert a picture to the PictureBox (Via the 'Picture' property).
'Now click on the picture. Every area that been clicked will be painted.
'Insert this code to the module :

Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal _
hObject As Long) As Long
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, _
ByVal Y As Long) As Long
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
Public Const FLOODFILLBORDER = 0
Public Const FLOODFILLSURFACE = 1

'Insert this code to your form:

Private Sub Form_Load()
Dim mBrush As Long
'Replace the '&H8080FF' below with your desirable painting color.
'You can change the BackColor property of any control you choose to your desirable
'color, and then Copy&Paste the color number from the BackColor propery cell.

mBrush = CreateSolidBrush(&H8080FF)
SelectObject Picture1.hdc, mBrush
Picture1.ScaleMode = vbPixels
DeleteObject mBrush
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As _
Integer, X As Single, Y As Single)
ExtFloodFill Picture1.hdc, X, Y, GetPixel(Picture1.hdc, X, Y), FLOODFILLSURFACE
End Sub

Go Back