Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to close this form by ESC key.

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
IN
lcPDF = getfile('PDF')
FrmHeight=600
FrmWidth =900
PUBLIC oForm
oForm = CREATEOBJECT('MyViewer',m.lcPDF)
oForm.Height=FrmHeight
oForm.Width=FrmWidth
oForm.Keypreview = .T.
oForm.Show()
Define Class myViewer As Form
Height=400
Width=600
Add Object htmlViewer As OleControl With ;
Height=FrmHeight-50,;
Width=FrmWidth,;
Anchor=15,OleClass='Shell.Explorer'
ADD OBJECT command1 AS commandbutton WITH ;
Top = FrmHeight-35, Left = FrmWidth-100, Height = 27, Width = 84, ;
Caption = "\<Close", Name = "Command1", cancel = .T.
ADD OBJECT command2 AS commandbutton WITH ;
Top = FrmHeight-35, Left = FrmWidth-200, Height = 27, Width = 84, ;
Caption = "\<E-Mail", Name = "Command2"
Procedure Init(tcFileName)
This.htmlViewer.Navigate2('file://'+m.tcFileName)
Endproc
Procedure htmlViewer.Refresh()
Nodefault
ENDPROC
PROCEDURE command1.Click
thisform.release()
ENDPROC
PROCEDURE command2.Click
WAIT WINDOW 'Mail in Process...'
ENDPROC
Enddefine
 
In Form.Keypress:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
If nKeyCode=27
   Thisform.release()
Endif
 
While dan's solution works in general, after you also set Form.KeyPreview = .T., I see you already have a commandbutton with thisform.release() in it's click, and that button is set as cancel button via Cancel=.T., which means the ESC key should trigger it's click.

So everything should work, but I assume ESC doesn't do anything, right?

I would investigate some settings, eg SET("ESCAPE"), ON("ESCAPE"). Something may overload the default behaviour.

Bye, Olaf.
 
In this case, Olaf, the Shell.Explorer object (which is displaying a PDF, which means Adobe's viewer object is in the works too) is taking focus and swallowing the escape key. Even the keypress method may not work but I didn't feel like testing it.
 
Thanks.

User is permitted to PDF as read-only. User should scroll pdf documents and zoom via Ctrl+ (+) and Ctrl+ (-) and nothing.

When I press ESC pdf-toolbar appears. If I disable toolbar completely. The ESC kay should work.

But I don't know how to disable toolbar. Switching On/Off toolbar can not solve the problem.

Thanks & Best Regards.
 
It may depend on the pdf viewer installed, as in the end it's the PDF viewer within the IE frame being active, swallowing the ESC key. In this csase, it's showing it's toolbar.

I tried to setfocus to the command1 button in form init, activate and to set the htmlViewer.Enabled=.F., tabstop=.F.
Something works, but only until you once activate the PDF, eg to scroll. Then key events seemed to be swallowed by Acrobat.

I can only wish you good lluck finding a solution.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top