Untuk Demo, silahkan copy-and-paste kode di bawah ini, kemudian jalankan di VFP!
*!* Code Starts Here:
oFrm = CREATEOBJECT("frmExitOnOutsideClick")
oFrm.Show(1)
Return
DEFINE CLASS frmExitOnOutsideClick AS form
DoCreate = .T.
Caption = "ExitOnOutsideClick Demo by Foxy"
Name = "frmExitOnOutsideClick"
ADD OBJECT label1 AS label WITH ;
WordWrap = .T., ;
Caption = "Click yang dilakukan di dalam form " + ;
"akan berfungsi seperti biasa. Tetapi, coba saja click " + ;
"di luar form ini. Otomatis form ini akan tertutup!" + CHR(13) + ;
"Grid di bawah ini hanya berfungsi untuk demo saja...", ;
Height = 72, ;
Left = 12, ;
Top = 6, ;
Width = 348, ;
Name = "Label1"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 216, ;
Left = 276, ;
Height = 27, ;
Width = 84, ;
Caption = "Click Me!", ;
Name = "Command1"
ADD OBJECT grid1 AS grid WITH ;
Height = 132, ;
Left = 12, ;
Top = 78, ;
Width = 348, ;
Name = "Grid1"
PROCEDURE clickme
lcMsg = "Click di terima oleh cmdClickMe.Click()" + CHR(13) + ;
"dan method ClickMe dijalankan..."
MESSAGEBOX(lcMsg, 64, "Click Me!")
ENDPROC
PROCEDURE Destroy
&& Kembalikan status ON KEY LABEL MOUSE ke default
ON KEY LABEL MOUSE
ENDPROC
PROCEDURE Click
&& Kalau click bukan terjadi di form ini, langsung keluar
IF !(MWINDOW() == ThisForm.Name)
ThisForm.Release()
ENDIF
ENDPROC
PROCEDURE Init
&& Rubah nama form supaya form dijamin unik
THISFORM.Name = SYS(2015)
&& Trap setiap mouse click di _Screen
&& ke event Click dari form ini:
ON KEY LABEL MOUSE _SCREEN.ActiveForm.Click()
ENDPROC
PROCEDURE command1.Click
&& Panggil method THISFORM.ClickMe()
THISFORM.ClickMe()
ENDPROC
PROCEDURE grid1.Init
CREATE CURSOR curTest (name C(30), address C(100))
SELECT curTest
APPEND BLANK
WITH THIS
.ColumnCount = 2
.AllowAddNew = .T.
.RecordSource = "curTest"
.Column1.Header1.Caption = "NAME"
.Column1.Width = 100
.Column2.Header1.Caption = "ADDRESS"
.Column2.Width = 200
ENDWITh
ENDPROC
ENDDEFINE
*!* Code Ends here
Happy coding!
Foxy