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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with setfous

Status
Not open for further replies.

bon011

Programmer
Jun 2, 2002
155
CZ
Hi,

I have an interesting problem.
In textbox keypress event I have this code:
----------------------------------------
LPARAMETERS nKeyCode, nShiftAltCtrl
if nKeyCode==13
thisform.command1.setfocus
endif
-----------------------------------------
But after I press ENTER in textbox so then is thisform.command1.click executed. And there is a prolem. I need only command1 to have the focus not to be clicked.

Any Idea why?????
 
I am guessing that the focus is going to the commandbutton and then the ENTER is happening which is causing the behavior you see. Try something like the following, it should fix your problem though I haven't tested it.

LPARAMETERS nKeyCode, nShiftAltCtrl
if nKeyCode==13
NODEFAULT &&Get rid of the ENTER
thisform.command1.setfocus
endif


Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Bon011

Move your code to the LostFocus of the textbox using:

Code:
IF lastkey()  = 13
  thisform.command1.SetFocus()
ENDIF

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
bon011,

I don't know what you meant by "no way", but I have just finished testing my suggestion in VFP7 and it works as advertised. If I comment out the line NODEFAULT and run it, pressing ENTER while in the Textbox will cause the commandbutton to fire its click event, but if I leave the NODEFAULT in the code everything works fine. Is there more going on here that you haven't told us, or did you mean something different by saying "no way"?

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Slighthaze

I tried to say that it doesn't work. I'm using vfp 6.0
 
MikeLewis

The dafault property was set to .F. and still is.
 
bon011,

Please cut and paste the code below into a prg and run it from within VFP. Let us know if it works like it should for you, I can't see how VFP 6 would work any different, and I am curious as to what is going on.

MikeLewis,

I thought you might be onto something with your idea about the Default property, however as the example below will show Default does not give the described behavior, not in VFP 7 anyways.

********SAMPLE CODE************
PUBLIC oForm
oForm = CREATEOBJECT("clsAvoidClick")
oForm.show()

DEFINE CLASS clsavoidclick AS form

Top = 0
Left = 0
Height = 198
Width = 337
DoCreate = .T.
Caption = "Form1"
Name = "clsavoidclick"
AutoCenter = .T.

ADD OBJECT text1 AS textbox WITH ;
Height = 23, ;
Left = 34, ;
TabIndex = 1, ;
Top = 36, ;
Width = 100, ;
Name = "Text1"

ADD OBJECT command1 AS commandbutton WITH ;
Top = 72, ;
Left = 34, ;
Height = 27, ;
Width = 84, ;
Caption = "Command1", ;
Default = .T., ;
TabIndex = 2, ;
Name = "Command1"

ADD OBJECT text2 AS textbox WITH ;
Height = 23, ;
Left = 202, ;
TabIndex = 3, ;
Top = 36, ;
Width = 100, ;
Name = "Text2"

ADD OBJECT label1 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "WITH NODEFAULT", ;
Height = 17, ;
Left = 34, ;
Top = 18, ;
Width = 107, ;
Name = "Label1"

ADD OBJECT label2 AS label WITH ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "WITHOUT IT", ;
Height = 17, ;
Left = 202, ;
Top = 18, ;
Width = 70, ;
Name = "Label2"

ADD OBJECT label3 AS label WITH ;
AutoSize = .F., ;
WordWrap = .T., ;
Alignment = 2, ;
BackStyle = 0, ;
Caption = "Try pressing ENTER in each of the above textboxes to see the difference.", ;
Height = 36, ;
Left = 58, ;
Top = 132, ;
Width = 216, ;
ForeColor = RGB(128,0,0), ;
Name = "Label3"

PROCEDURE text1.KeyPress
LPARAMETERS nKeyCode, nShiftAltCtrl
if nKeyCode==13
NODEFAULT &&Get rid of the ENTER
thisform.command1.setfocus
endif
ENDPROC

PROCEDURE command1.Click
MESSAGEBOX("I was Clicked!")
ENDPROC

PROCEDURE text2.KeyPress
LPARAMETERS nKeyCode, nShiftAltCtrl
if nKeyCode==13
thisform.command1.setfocus
endif
ENDPROC

ENDDEFINE



Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
You I tried it. It works exactly as I wont.
Perhaps I made some mistake before.

Thanks
 
MikeLewis,

And a good thought too, I was wracking my brain trying to figure out what could possibly be different to cause the behavior bon011 was seeing. I didn't even think of Default, not because I had ruled it out, but simply because I didn't think of it. As you know thinking outside the box like that is usually very good in a situation like this. Thank goodness bon011 found that a mistake had been made or I may not have gotten any work done today. [smile]

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Craig,
I found that your code works the same under VFP 5.0 SP3, VFP 6.0 SP5, VFP 7.0 SP1 and VFP 8.0 SP1 (as expected)!

Rick
 
rgbean,

Thanks for testing that out for us.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top