Canvas.MouseDown Click at wrong location fire correct Method

I wasted too many hours on this, enough hours to understand where the problem lies.

The code below is in the Canvas.MouseDown Event.

When I click at X,Y: 301,55, the second part is drawn (Draw_Son_Grand("List_Data")).

But that cannot be: watch carefully the Rect_Son values for Y.
[Worst: the click is located in the Rect_Father Y displayed area, 15 pixels above the Rect_Son.Top value !.]

Relevant part of the used code:

[code] // Fills the Father_Rect Structure
Rect_Father = New Realbasic.Rect
Rect_Father.Left = 20 // X
Rect_Father.Top = 20 // Y
Rect_Father.Width = 385
Rect_Father.Height = 50

// Fills the Son_Rect Structure
Rect_Son = New Realbasic.Rect
Rect_Son.Left = 40 // X
Rect_Son.Top = 70 // Y
Rect_Son.Width = 470 // Arbitrary value
Rect_Son.Height = 450 // Arbitrary value

// Rect_Father holds the X,Y, W,H of the file name (no Extension) and the # of available TABLE(s)
If Rect_Father.Contains(RB_Point) Then
// Draw the list of Tables / # Of Record(s)
Draw_Son()

// Handled
Return True

End If

// Rect_Son holds the X,Y, W,H of the list of TABLE(s)
If Rect_Son.Contains(RB_Point) Then
// Yes ! Draw That TABLE’s Columns Names
Draw_Son_Grand(“List_Data”) // Set a TABLE default name (for testings)

// Handled
Return True

End If

// Event Handled
Return True[/code]

Help is welcome.

I forgot to say that I started to use single if X and Y to determine where the click was done:

If (X > 19 And X < 421) And (Y > 19 And Y < 61) Then

and I already had troubles with that, thus the changes.

Now, it may be my design that is wrong (how ?)

Where do you define RB_Point?
How and where do you assign values to it?

If you are having issues with the IF at the bottom, then something else is causing these issues.

Put some debugging through the Method to find the location of the problem:

system.DebugLog("x=" + str(x) + " y=" + str(y) + "RB_Point.x=" + str(RB_Point.x) + " RB_Point.y=" + str(RB_Point.y))

Thank you Julian.

[quote=410815:@]Where do you define RB_Point?
How and where do you assign values to it?[/quote]
Good questions:

[code] Dim RB_Point As New Realbasic.Point

RB_Point.X = X
RB_Point.Y = Y[/code]

I love to use system.DebugLog !

I also discovered (somewhere ?) MouseMove: I use it now to report the Mouse location (X,y) in a TextField at the window bottom.

Also: I created a brand new project to try to make the code working (to be sure the other parts of the project does not interfere with that code).

I am quite capable of walking next to my shoes, but what I want to do is so simple that I wonder how it would be possible!

Unless the mistake is so big that I do not see it!

I will start a brand new project with two simple bitmap rectangles that draws simple graphics figures from nothing (no copy/paste code, no file loading…) in a few minutes.

I’ve may use a wrong y value. I have to inspect my brand new project/code a bit more and check the previous one with that in mind. But I took the values in the MouseMove reported values.

If this is the answer, I had a large stone between the screen and my eyes :frowning: (or ;).

Preliminary changes seems to resolve the trouble: the Y values were wrong (apparently).

Sorry for the buzz.

Nota: even with a fresh eye earlier today and a goo sleep, I do not saw that :frowning:

No worries, you can stare at the same bug for a while and never see it :slight_smile: Glad you got it sorted

Thank you.