FIX: Can't Move Focus from a Toolbar to an Object on a Form
ID: Q132910
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b
SYMPTOMS
Attempts to use SetFocus to move the focus from an object in a toolbar to
an object on a form within a formset does not work. The focus never leaves
the previously active control, which is another object on the form. This
problem occurs only with formsets.
WORKAROUND
Step-by-Step Workaround
Create an instance of the toolbar as a separate object and the form as a
separate object. Then the code _SCREEN.ActiveForm.Text1.SetFocus
in the command button on the toolbar works just fine. For example:
- Use this command:
MODIFY FORM Myformset
- Select the ToolBar1 form.
- On the Form menu, click Remove Form.
- Press CTRL+W to save your work and exit from the Form Designer.
- Use this command:
MODIFY CLASS mytoolbar OF mytestlib
- Double-click the command button on the Toolbar.
- Replace this code:
THISFORMSET.FORM1.Text1.SetFocus
with this code:
_SCREEN.ActiveForm.Text1.SetFocus
- Press CTRL+W to save your work and exit from the Class Designer.
- Type the following commands in the Command window:
SET CLASSLIB TO mytestlib.vcx
oToolBar = CREATEOBJECT("mytoolbar")
oToolBar.SHOW
DO FORM myformset.
- Click the second text box object (the one below) on Form1.
- Click the New button on the toolbar.
Alternative Step-by-Step Workaround
Another workaround if you must use a formset is to place a timer object on
the form that uses SetFocus to move the focus to Text1 on the form. For
example:
- Use the following command:
MODIFY CLASS mytoolbar OF mytestlib.
- Double-click the command button on the toolbar.
- Replace this code:
THISFORMSET.FORM1.Text1.SetFocus
with this code:
THISFORMSET.FORM1.Timer1.Enabled = .T.
- Add a timer object to Form1.
- Set the timer's Interval property to 10.
- In the timer's Timer event, add this code:
THISFORMSET.FORM1.Text1.SetFocus
THIS.Enabled=.F.
- Press CTRL+W to save the formset and exit from the Form Designer.
- Use this command:
DO FORM myformset
- Click the second Text Box object (the one below) on Form1.
- Click the New button on the toolbar.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article. This problem has been fixed in
Visual FoxPro 5.0 for Windows.
MORE INFORMATION
Steps to Reproduce Problem
- Use this command:
CREATE CLASS mytoolbar OF mytestlib AS TOOLBAR
- Add a command button to the toolbar.
- Set the command button's Caption property to New.
- Type the following code to the command button's Click event:
THISFORMSET.FORM1.Text1.SetFocus
- Press CTRL+W to save your work and exit Class Designer.
- Use this command:
CREATE FORM myformset.
- Click the View Classes button, and add MYTESTLIB.VCX.
- Add mytoolbar to the form. It will display a message box with the
following message. Click the Yes button.
A form set object is required to add a form. Create one?"\
- Move Form1 to the right so that both forms can be seen.
- Click the View Classes button, and choose standard.
- Add two text box objects (one below the other) to Form1.
- Press CTRL+W to save your work and exit Form Designer.
- Use this command:
DO FORM myformset.
- Click the second Text Box object (the one below) on Form1.
- Click the New button on the toolbar.
This should set the focus to Text1, the first text box object on Form1.
However, the focus never leaves the previously active control (Text2), the
second text box object on Form1. The code executed in the
MYTOOLBAR.Command1.Click event to shift focus from the previously active
control to Text1 does not work.
Additional query words:
Keywords : kbVFp kbVFp300bbug kbVFp500fix buglist3.00 FxtoolFormdes
Version : WINDOWS:3.0,3.0b
Platform : WINDOWS
Issue type :