Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Act on a DoubleClick event
Message
De
05/06/2005 11:06:59
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01019702
Message ID:
01020336
Vues:
21
>Hi.
>Is there any way , within a form, of running code on a DoubleClick (or Return Key) event thats pressed from within a grid.
>I want to exit the form if either the DobleClick or the Return key is pressed inside in the grid.
>
>Now, I know I can do this on the the control within the Grid, but this means changing all my base classes and I dont want to do that.
>Nor is it that easy to 'over-ride' the doubleclick event of the control in the grid as the fields within the Grid are data driven from my framework (i.e. The Grid itself does not have any controls.. these are added programaticlly)
>
>Idealy what I would like to be able to do is something like:
>
>On Key DoublClick (In the Grid) Or On Key Return(in the Grid)
> SomeCode Here
> Thisform.Release
>
>Any help appreciated
>
>Regards,
>Gerard

You can put this logic into your Form subclass.
PUBLIC oform1

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

DEFINE CLASS demoForm AS myForm

	Height = 478
	Width = 362
	Autocenter = .T.
	Caption = "Global Form Input"
	Name = "form1"
	SHOWWINDOW = 2

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 20, ;
		Left = 104, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"

	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 2, ;
		Height = 368, ;
		Left = 28, ;
		Top = 72, ;
		Width = 308, ;
		Name = "Grid1"

	PROCEDURE _userinput
		LPARAMETERS codeEvent

		WAIT CLEAR && for this demo

		IF m.This.ActiveControl=m.This.Grid1
			DO CASE
				CASE m.codeEvent=1 && Enter
					thisform.Command1.Click
					RETURN .F. && consume the key
				CASE m.codeEvent=2 && Left   Click
					thisform.Grid1.Click
				CASE m.codeEvent=3 && Double Click
					thisform.Grid1.DblClick(.T.)
			ENDCASE
		ENDIF
	ENDPROC

	PROCEDURE LostFocus
		DODEFAULT()
		
		WAIT CLEAR && for this demo

	ENDPROC


	PROCEDURE Load
		CREATE CURSOR testgrid (f1 i DEFAULT RAND()*1000,F2 I DEFAULT RAND()*1000000)
		FOR k=1 TO 100
			APPEND BLANK
		NEXT
		LOCATE
	ENDPROC


	PROCEDURE grid1.DblClick
		LPARAMETERS FormCall
		* uses this.GridHitTest()
		IF m.FormCall
			WAIT windows "GRID dblclick !!" NOCLEAR NOWAIT TIMEOUT 5
		ELSE
			* dblclick on grid area
		ENDIF
	ENDPROC


	PROCEDURE grid1.Click
		WAIT windows "GRID cliCk !!" NOCLEAR NOWAIT TIMEOUT 5
	ENDPROC

	PROCEDURE command1.Click
		WAIT windows "COMMAND CLICK !!" NOCLEAR NOWAIT TIMEOUT 5
		RETURN .F. && ENTER IS consumed
	ENDPROC

ENDDEFINE

* FORM CLASS
DEFINE CLASS myForm AS form
	PROTECTED dblClickTimeOut	&& Correct is HIDDEN
	
	dblClickTimeOut = DAY(NULL)

	PROCEDURE userinput	&& correct is a PROTECTED Method
		LPARAMETERS inputCode && this is a protected form class event
		DO CASE
			CASE m.inputCode = 1 && ENTER
				IF this._UserInput(1) && return .t. don't consume ENTER
					KEYBOARD '{ENTER}' PLAIN
				ENDIF
			CASE m.inputCode = 2 && LEFT CLICK
				LOCAL eventTime,dblClickEvent
				STORE DATETIME()-{^2000/01/01:} + SECONDS() % 1 TO eventTime
				STORE m.eventTime < m.Thisform.dblClickTimeOut	TO dblClickEvent
				Thisform.dblClickTimeOut = m.eventTime + _dblclick
				this._UserInput(IIF(m.dblClickEvent,3,2))
		*	.... others cases
		ENDCASE
	ENDPROC

	PROCEDURE _userinput
		LPARAMETERS codeEvent && this is the PUBLIC CLASS event

	PROCEDURE Destroy
		* BINDEVENT filler
	ENDPROC

	PROCEDURE LostFocus
		UNBINDEVENTS(m.This,"Destroy",m.This,"LostFocus") && A VFP BUG REQUIRE THIS
		
		ON KEY LABEL LEFTMOUSE
		ON KEY LABEL ENTER
		
		WAIT CLEAR && for this demo

	ENDPROC

	PROCEDURE GotFocus
		ON KEY LABEL ENTER 			_screen.ActiveForm.UserInput(1)
		ON KEY LABEL LEFTMOUSE		_screen.ActiveForm.UserInput(2)
		
		BINDEVENT(m.This,"Destroy",m.This,"LostFocus") && A VFP BUG REQUIRE THIS
	ENDPROC

ENDDEFINE
On VFP9 ON KEY LABEL can to be exchanged with BINDEVENT(thisform.hwnd,...)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform