Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 To: Alex Gefter
  Where is Alex Gefter?
 Detroit
 Michigan - United States
 Alex Gefter
 Tags
Subject: RE: Set Focus
Thread ID: 232008 Message ID: 232057 # Views: 30 # Ratings: 0
Version: Visual FoxPro 7 Category: General VFP Topics
Date: Friday, June 19, 2009 11:04:34 AM         
   


> Hello,
> I am having difficulty in setting focus on the control I need.
>
> Here is the situatuion.
>
> On my form, I have a textbox that accepts only scans and a button. The button is not enabled until the scan happens.
> There are no keyboard or mouse - just a barcode scanner and a touch screen.
>
> The button should only appear after the barcode is scanned and verified. At this point my barcode is saved and the textbox is cleared. Button only should serve as an available option.
>
> My problem is to return the focus to the textbox and not have it on the button at all.
>
> I am trying to use Control.SetFocus but it doesn't work...
>
> Thank you for your help.
>
>
>
> AG


I assume you have any number of controls on your form and you want to focus only in your form.text1 :
if form.init
bindevent(thisform.text1,"lostfocus",thisform,"ybind")
thisform.text1.setfocus


create a new method ybind on your form and put in
nodefault
thisform.text1.setfocus


anywhere you click or want to gotfocus on your form ,only the text1 receive the focus :-)

this is a test form.You can cut the property selectOnEntry in the text1 if you want.
try to type anything.
*--Author Yousfi Benameur El Bayadh Algeria
*--Time stamp vendredi 19 juin 2009; 10:13:51
*--Subject :Stay always focus in a textbox on a form

PUBLIC yForm
yForm=NEWOBJECT("asup")
yForm.Show
RETURN

DEFINE CLASS asup AS form
	Height = 279
	Width = 713
	ShowWindow = 2
	DoCreate = .T.
	AutoCenter = .T.
	BorderStyle = 3
	Caption = ""
	MaxButton = .F.
	BackColor = RGB(255,128,0)
	Name = "asup"

	ADD OBJECT command3 AS commandbutton WITH ;
		Top = 240, ;
		Left = 576, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Exit", ;
		Name = "Command3"

	ADD OBJECT text1 AS textbox WITH ;
		FontSize = 16, ;
		Height = 85, ;
		Left = 36, ;
		SelectOnEntry = .T., ;
		Top = 36, ;
		Width = 169, ;
		ForeColor = RGB(0,255,0), ;
		Name = "Text1"

	ADD OBJECT text2 AS textbox WITH ;
		Height = 48, ;
		Left = 396, ;
		Top = 24, ;
		Width = 204, ;
		Name = "Text2"

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

	ADD OBJECT text3 AS textbox WITH ;
		Height = 49, ;
		Left = 408, ;
		Top = 84, ;
		Width = 192, ;
		Name = "Text3"

	ADD OBJECT edit1 AS editbox WITH ;
		Height = 108, ;
		Left = 216, ;
		Top = 144, ;
		Width = 193, ;
		Name = "Edit1"

	PROCEDURE ybind
		nodefault
		thisform.text1.setfocus
	ENDPROC

	PROCEDURE Init
		bindevent(thisform.text1,"lostfocus",thisform,"ybind")
		thisform.text1.setfocus
	ENDPROC

	PROCEDURE Destroy
		clea events
	ENDPROC

	PROCEDURE command3.Click
		CLEAR
		thisform.release
	ENDPROC


ENDDEFINE
*
*-- EndDefine: asup


Dont rate please.its only for the pleasure to help.Give me only a feed back.
Yousfi Benameur



COMPLETE THREAD
Set Focus Posted by Alex Gefter @ 6/18/2009 9:35:35 PM
RE: Set Focus Posted by Cetin Basoz @ 6/18/2009 9:57:42 PM
RE: Set Focus Posted by Andy Kramek @ 6/18/2009 11:13:21 PM
RE: Set Focus Posted by Ammar Hadi @ 6/19/2009 2:35:15 AM
RE: Set Focus Posted by Yousfi Benameur @ 6/19/2009 11:04:34 AM