Microsoft KB Archive/156243

= PRB: Closing SDI Form with Menu Causes Objects to Shift Upward =

Article ID: 156243

Article Last Modified on 12/14/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition

-



This article was previously published under Q156243



SYMPTOMS
If a Single-Document Interface (SDI) or Top-Level form (form with the ShowWindow property set to 2 - As Top-Level Form) has a menu, releasing the form causes the controls contained within the form to momentarily shift upward before the form disappears.



WORKAROUND
Set the form's Visible property to .F. - False before releasing the form. See the MORE INFORMATION section below for details on implementing this.



STATUS
This behavior is by design.



MORE INFORMATION
Visual FoxPro 5.0 gives you the ability to create forms that can appear outside of (or in lieu of) the FoxPro desktop, and appear in the task list or on the task bar. These forms are called Top-Level, or SDI, forms, and require setting the form's ShowWindow property to "2 - As Top-Level Form." You can add menus, toolbars, and child forms to these forms in the same way you add them to the Visual FoxPro desktop in this and previous versions of Visual FoxPro.

Steps to Reproduce Behavior
 Create a form called Test. Set the form's ShowWindow property to 2 - As Top-Level Form in the Form Designer Property window.  Add a command button to the form, and set its Caption property to Close. Place the following code in the Click method of this command button: THISFORM.Release   In the Init method of the form, add the following code: DO TESTMENU.MPR WITH THIS, .T.                        Create a new menu. Make it a Menu rather than a Shortcut. Select Menu then Quick Menu from the FoxPro menu bar to create a default quick menu.</li> On the View menu, click General Options. In the General Options dialog box, select the Top-Level Form check box, then click OK.</li> On the Menu menu, click Generate. Save the menu as Testmenu, then select the Generate button to generate the default .mpr file.</li> Run the Test form, then click the Close button. The Close button shifts upward on the form, then the form closes. This shift also occurs if the form is closed in any of the following ways: Clicking Close on the File menu; clicking the Close button [X] in the upper right corner of the form under Windows 95 or NT 4.0; or pressing Alt+F4 or clicking Close on the Control menu.</li></ol>

The workaround is to make the form invisible immediately before releasing it. Because a form may be closed in several different ways, the workaround must be incorporated in several places. Here is sample code to demonstrate this.

To handle when the form is closed by clicking a command button, place the following in the Click method code for your Quit or Close command button: * Close button Click code THISFORM.Visible = .F.  THISFORM.Release To handle when the form is closed by clicking the Close [X] button under Windows 95 or NT 4.0, or pressing Alt+F4 or clicking Close on the Control menu, place the following in the QueryUnload method code for the form: * Form.QueryUnload code THIS.Visible = .F. To handle when the form is released by clicking Exit (or equivalent) from the menu on the SDI form, add this to a procedure for the Exit bar of your menu: * Menu Exit bar code LOCAL oForm oForm = _screen.ActiveForm _screen.ActiveForm.Visible = .F.  oForm.Release SET SYSMENU TO DEFAULT   && Resets VFP menu back to default

Keywords: kbui kbprb KB156243

-

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

© Microsoft Corporation. All rights reserved.