 |
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

November 10th, 2005, 06:11 AM
|
Registered User
|
|
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Point Function
Hi All,
Point function of Form object returns color of the pixel at a
partcular location on the form.
I tried to use this function in a project of Graphics.
I found that the behaviour of the function was strange.
Sometimes, the function returned a color value upon clicking
a pixel on form.
Other times, it simply falied to return anything.
It just kept returning -1 eventhought the color of the pixel was red.
The same code worked on other PCs while on still others it failed.
Can anyone explain why Point function behaves like this ?
I need a quick reply.
Thank you.
|

November 10th, 2005, 02:31 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Read the remarks at the end of the Point documentation:
"If the point referred to by the x and y coordinates is outside object, the Point method returns -1."
Marco
|

November 15th, 2005, 02:09 AM
|
Registered User
|
|
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for your reply.
I read the remark at the end but strangely the behaviour of the
function did not change.
The remark was in my mind when first time I wrote the post.
Even when the point referred to by x and y is inside the object, the Point function returns -1. To realise this, just play a little with it and you will understand what I am trying to say. Thats why I said that the same code runs on some machines and fails on other machines.
I hope this makes things clear.
|

November 15th, 2005, 02:24 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
a negative value for the color means a system color, that you can map back to an rgb triplet using the GetSysColor API
but before doing that, check if the color setting (that is, number of colors) is the same for all computers
Marco
PS are you really really sure that the coordinates you use are inside the client area of the form? how do you get them? Keep in mind that if the cursor is above a control (like a textBox), Point will return -1
|

November 18th, 2005, 02:41 AM
|
Registered User
|
|
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I am totally sure that the coordinates I use is totally inside my client area.
If you have heard of Boundary Filling algorithm in Computer Graphics, the following code will be easy to understand.
Properties :
Form Object :
BackColor = Black
ForeColor=White
ScaleMode=Pixel
WindowState=Maximized
Command 1 :
Name : cmdDS
Caption : Draw Square
Command 2 :
Name : cmdDC
Caption : Draw Circle
Command 3 :
Name : cmdAF
Caption : Activate Filling
Command 4 :
Name : cmdClear
Caption : Clear
Command 5 :
Name : cmdExit
Caption : Exit
Place labels on form as shown in the interface. Set BackColor property of every label to color shown in the interface.
Code :
Dim FillCol As ColorConstants
Dim BoundaryCol As ColorConstants
Dim ActivateFill As Boolean
Private Sub Form_Load()
ActivateFill = False
BoundaryCol = vbCyan
End Sub
Private Sub cmdDS_Click()
Dim x1 As Integer
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
x1 = InputBox("Enter x1", 0)
y1 = InputBox("Enter y1", 0)
x2 = InputBox("Enter x2", 0)
y2 = InputBox("Enter y2", 0)
Me.Line (x1, y1)-(x2, y2), BoundaryCol, B
End Sub
Private Sub cmdDC_Click()
Dim xc As Integer
Dim yc As Integer
Dim rad As Integer
xc = InputBox("Enter xc", 0)
yc = InputBox("Enter yc", 0)
rad = InputBox("Enter radius", 0)
Me.Circle (xc, yc), rad, BoundaryCol
End Sub
Private Sub cmdAF_Click()
If ActivateFill = False Then
ActivateFill = True
End If
End Sub
Private Sub cmdClear_Click()
Me.Cls
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Public Sub BoundaryFill4(xf As Single, yf As Single, FillCol As ColorConstants, BoundaryCol As ColorConstants)
Dim current As ColorConstants
current = Point(xf, yf)
If ((current <> BoundaryCol) And (current <> FillCol)) Then
Me.PSet (xf, yf), FillCol
Call BoundaryFill4(xf + 1, yf, FillCol, BoundaryCol)
Call BoundaryFill4(xf - 1, yf, FillCol, BoundaryCol)
Call BoundaryFill4(xf, yf + 1, FillCol, BoundaryCol)
Call BoundaryFill4(xf, yf - 1, FillCol, BoundaryCol)
End If
ActivateFill = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If ActivateFill Then
Call BoundaryFill4(X, Y, FillCol, BoundaryCol)
End If
End Sub
Note : The code given below is only of label1. Repeat the same code for all labels.
Private Sub Label1_Click()
FillCol = Label1.BackColor
End Sub
|

November 18th, 2005, 11:15 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
in your forms there are command buttons and labels. when the filling algorithm reaches one of the controls, Point returns -1
You just have to handle that case:
if me.point(x,y) = -1 then exit sub
Marco
|
|
 |