Wrox Programmer Forums
|
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
 
Old November 10th, 2005, 06:11 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old November 10th, 2005, 02:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 15th, 2005, 02:09 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old November 15th, 2005, 02:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 18th, 2005, 02:41 AM
Registered User
 
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old November 18th, 2005, 11:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any point RobReid Flash (all versions) 0 September 26th, 2008 09:07 AM
Decimal point marcusbris Visual Basic 2005 Basics 3 January 18th, 2007 05:55 AM
Can anyone point out my error please.... Jinn SQL Server 2000 1 November 19th, 2006 11:47 PM
Decimal Point interrupt Javascript How-To 4 March 16th, 2005 05:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.