Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object and the Mouse
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00428423
Message ID:
00428660
Vues:
10
>>I want position the mouse on a label or text control but I don't know where is the control on my form.
>
>Screen and mouse co-ords are not in the same units (scale) so some fudging is required. In the following my form has three text boxes (Text1 through Text3) and a sinlge command button. Clicking or pressing enter on the command button causes the mouse pointer cycle across the three text boxes.
*- Form1.Command1.Click()
>
>WITH This
>   DO CASE
>      CASE .Caption = "One"
>        .Caption = "Two"
>        iTargetX = ThisForm.Text1.Top
>        iTargetY = ThisForm.Text1.Left
>      CASE .Caption = "Two"
>        .Caption = "Three"
>        iTargetX = ThisForm.Text2.Top
>        iTargetY = ThisForm.Text2.Left
>      OTHERWISE
>        *- Must be Three so set back to "One".
>        .Caption = "One"
>        iTargetX = ThisForm.Text3.Top
>        iTargetY = ThisForm.Text3.Left
>   ENDCASE
>ENDWITH
>
>MOUSE AT iTargetX / 15, iTargetY / 5 ;
>	WINDOW (ThisForm.Caption)
>
>RETURN .T.


Hi Houston,

This is not exactly correct.
You don't need to perform any calculations if you use PIXELS clause in MOUSE command.

Second, your way will not work properly if the control is inside the container on the form.
The easiest way to get it's coordinates relative to the form is to use OBJTOCLIENT() function.

Third, your sample will not work properly if there are several instances of the same form. There is a bug related to ... WINDOW clause
(no matter if you use WINDOW WONTOP() or WINDOW (thisform.caption) ).
In such situation VFP is not sure in which window to place the cursor.

Here is the code for the sample form which will work properly in all circumstances.
The form gets renamed on the fly and back to original name.
**************************************************
*-- Form:         form1 (d:\prg\test\form1.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*
DEFINE CLASS form1 AS form


	DataSession = 1
	Top = 0
	Left = 0
	Height = 295
	Width = 434
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 240, ;
		Left = 312, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "1", ;
		Name = "Command1"


	ADD OBJECT text1 AS textbox WITH ;
		Value = "text1", ;
		Height = 23, ;
		Left = 12, ;
		Top = 24, ;
		Width = 100, ;
		Name = "Text1"


	ADD OBJECT text2 AS textbox WITH ;
		Value = "text2", ;
		Height = 23, ;
		Left = 12, ;
		Top = 72, ;
		Width = 100, ;
		Name = "Text2"


	ADD OBJECT text3 AS textbox WITH ;
		Value = "text3", ;
		Height = 23, ;
		Left = 12, ;
		Top = 120, ;
		Width = 100, ;
		Name = "Text3"

	PROCEDURE command1.Click
		LOCAL loObject, lnLeft,lnTop, lcName 
		loObject = EVAL("thisform.text" + this.caption) && get the object reference to the desired control
		lnLeft = OBJTOCLIENT(loObject, 2) && 2 - left 
		lnTop = OBJTOCLIENT(loObject, 1) && 1 - top

		this.caption = IIF(this.caption = "1", "2", IIF(this.caption = "2", "3", "1")) && change caption after each click

		lcName = thisform.name
		thisform.name = SYS(2015) && There is the bug in WINDOW clause if you have multiple instances of the same form
		MOUSE AT lnTop, lnLeft WINDOW (WONTOP()) PIXELS
		thisform.Name = lcName
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform