Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting a Click on a line object
Message
 
À
11/08/2005 22:08:38
Scott Butts
Ims Specialty Services
Twin Falls, Idaho, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01040465
Message ID:
01040476
Vues:
17
This message has been marked as the solution to the initial question of the thread.
This post definitely caught my eye... I've worked on a number of CAD and Construction Blueprint manipulation projects in Visual FoxPro and this is one of the things that really created some havoc the first time I ran into it (that and creating and shading irregular shapes - though Visual FoxPro 9 fixed that with the advent of the polypoints property). Anyways, the solution I came up with was not as hard as it first looked to figure out whether the mouse is over the line. Here's a working example... just cut-n-paste into a prg file and run it. Then pass your mouse over the lines and as the mouse is directly over the line it will change the line's color so you know that it's being detected. The important code is in the lineex class's mousemove event, just place that type of code in your line's mousedown event to decide whether the click is to be considered an "actual" click or not.
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form

	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"

	ADD OBJECT line1 AS lineex WITH ;
		BorderWidth = 3, ;
		Height = 156, ;
		Left = 60, ;
		Top = 48, ;
		Width = 132, ;
		Name = "Line1"

	ADD OBJECT line2 AS lineex WITH ;
		BorderWidth = 3, ;
		Height = 120, ;
		Left = 204, ;
		Top = 24, ;
		Width = 156, ;
		LineSlant = "/", ;
		Name = "Line2"
ENDDEFINE

DEFINE CLASS lineex as Line

	PROCEDURE MouseMove
		PARAMETERS nButton, nShift, nXCoord, nYCoord
		LOCAL lnFullX, lnFullY, lnCurrentX
		lnFullX = this.Width
		lnFullY = this.height
		lnCurrentXPercentage = (nXCoord - this.Left)/lnFullX

		IF This.LineSlant = "/"
			lnCurrentXPercentage = (1 - lnCurrentXPercentage)
		ENDIF

		*!* Is mouse directly over the line?
		*!* if so, color it red
		IF BETWEEN((nYCoord - this.Top) / lnCurrentXPercentage, lnFullY - this.BorderWidth, lnFullY + this.BorderWidth)
			this.BorderColor = RGB(255,0,0) 
		ELSE
			this.BorderColor = RGB(0,0,0) 
		ENDIF
	ENDPROC
ENDDEFINE
>I have a line object slanting from left to right (so the line object is kind of a square). Clicking anywhere on the object (even not on the actual line) causes the click event to fire. How would I be able to detect if the users actually clicked on the line part of the line object? Anybody have some suggestions.
>
>I need to do this becuase there are objects behind this line object that needs to respond to mouse events, I want to pass the event to those objects if the users did NOT click on the visible line.
>
>Thanks for any help.
>
>Scott
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform