Microsoft KB Archive/132910

= FIX: Can't Move Focus from a Toolbar to an Object on a Form =

Article ID: 132910

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q132910



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.



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 </li> Press CTRL+W to save your work and exit from the Class Designer.</li>  Type the following commands in the Command window: SET CLASSLIB TO mytestlib.vcx oToolBar = CREATEOBJECT("mytoolbar") oToolBar.SHOW DO FORM myformset. </li> Click the second text box object (the one below) on Form1.</li> Click the New button on the toolbar.</li></ol>

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: <ol> Use the following command:

MODIFY CLASS mytoolbar OF mytestlib.

</li> Double-click the command button on the toolbar.</li>  Replace this code: THISFORMSET.FORM1.Text1.SetFocus with this code: THISFORMSET.FORM1.Timer1.Enabled = .T.                   </li> Add a timer object to Form1.</li> Set the timer's Interval property to 10.</li>  In the timer's Timer event, add this code: THISFORMSET.FORM1.Text1.SetFocus THIS.Enabled=.F.                   </li> Press CTRL+W to save the formset and exit from the Form Designer.</li> Use this command:

DO FORM myformset

</li> Click the second Text Box object (the one below) on Form1.</li> Click the New button on the toolbar.</li></ol>

<div class="status_section">

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.

<div class="moreinformation_section">

Steps to Reproduce Problem
<ol> Use this command:

CREATE CLASS mytoolbar OF mytestlib AS TOOLBAR

</li> <li>Add a command button to the toolbar.</li> <li>Set the command button's Caption property to New.</li> <li> Type the following code to the command button's Click event: THISFORMSET.FORM1.Text1.SetFocus </li> <li>Press CTRL+W to save your work and exit Class Designer.</li> <li>Use this command:

CREATE FORM myformset.

</li> <li>Click the View Classes button, and add MYTESTLIB.VCX.</li> <li>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?"\

</li> <li>Move Form1 to the right so that both forms can be seen.</li> <li>Click the View Classes button, and choose standard.</li> <li>Add two text box objects (one below the other) to Form1.</li> <li>Press CTRL+W to save your work and exit Form Designer.</li> <li>Use this command:

DO FORM myformset.

</li> <li>Click the second Text Box object (the one below) on Form1.</li> <li>Click the New button on the toolbar.</li></ol>

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.

Keywords: kbbug kbfix kbvfp500fix KB132910

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.