Sheets, controls, and focus
Posted: Fri Aug 07, 2009 12:47 pm
by ConvertFromOldNGs
by Nige >> Thu, 10 Mar 2005 9:03:11 GMT
Hi all
I am wondering if it is possible to remember the control of a given sheet, so when you switch from one sheet to another and back again, you can return to the control you were on in the first place
thanks in advance
Re: Sheets, controls, and focus
Posted: Fri Aug 07, 2009 12:47 pm
by ConvertFromOldNGs
by cnwjhp1 >> Fri, 11 Mar 2005 4:33:38 GMT
You can store a reference on the form, of type Control, and send the setFocus message to it. The trick then is to know when to save off the reference, and when to setFocus to it.
As an example, I added a few lines of code to a form that has a folder fld1 with two sheets shtNames and shtParams. Using the class browser (not Painter), I added references shtNamesCtl and shtParamsCtl to the form, both of type Control.
The sheet shtNames has two textboxes, txtName and txtDesc. I put this line in the gotFocus method of each:
shtNamesCtl:=textbox;
Then I put this in the sheetChg method of the folder fld1:
if folder.topSheet=shtNames then
if shtNamesCtl<>null then
shtNamesCtl.setFocus;
endif;
// elseif folder.topSheet=shtParams then
endif;
After these changes, when I click back to the shtNames sheet, focus is returned to the right control.
This solution obviously requires a bit of hard-coding, but it may be suitable for simple situations. There may be a more general solution, eg subclassing Folder and/or Sheet to add the Control reference to the Sheet itself.
Cheers,
John P