Microsoft KB Archive/190069

= How to show a Print Preview window as MDI child of Top-Level form =

Article ID: 190069

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q190069



SUMMARY
Starting with Visual FoxPro 5.0, you may create top-level forms that do not require the Visual FoxPro desktop to display. If you display a report preview within a top-level form, you must first display the Visual FoxPro desktop for the report preview to be visible.

Visual FoxPro 6.0 has added the capability for displaying report previews within top-level forms. This article describes how to display a report preview as a multiple document interface (MDI) child window within a top- level form, and also shows how to size the preview to the top-level form.



MORE INFORMATION
Below is an example that demonstrates the display of a report preview as an MDI child of a top-level form. Through code, we create a table and a report, then create and show a top-level form.

Once the form is visible, you can display the report preview by clicking the "Report Preview" CommandButton.

The preview can be displayed in one of two ways, either in an MDI child window the same size as the top-level form (the default, with the check box selected), or in an MDI child window maximized within the top-level form (by clearing the check box).

  Run the following code from a program (.prg) file: CLEAR ALL PUBLIC oform LOCAL lnI CLOSE DATA ALL Delete file table_1.dbf CREATE TABLE table_1 (field1 C(10)) FOR lnI = 1 TO 3 INSERT INTO table_1 VALUES ('xx') ENDFOR Delete file report_1.fr? CREATE REPORT report_1 FROM table_1

oform=CREATEOBJECT("TL_form") oform.SHOW READ EVENTS CLOSE TABLES

DEFINE CLASS TL_form AS FORM BorderStyle = 3 ShowWindow = 2 AutoCenter = .T.        lIsFormUp=.F.         Width = 500

ADD OBJECT commandpreview AS COMMANDBUTTON WITH ; TOP = 180, ; LEFT = 210, ; HEIGHT = 27, ; WIDTH = 95, ; CAPTION = "Report Preview", ; NAME = "Commandpreview"

PROCEDURE DESTROY Clear EVENTS _SCREEN.VISIBLE=.T.           SET SYSMENU TO DEFAULT ENDPROC

PROCEDURE ACTIVATE IF !THIS.lIsFormUp _SCREEN.VISIBLE = .f.  && We wait till now to hide desktop && to ensure SDI form is active window. this.lIsFormUp = .T.           ENDIF ENDPROC

ADD object chkType as checkbox with ; top = 20, ; caption = 'Check to preview in window sized to form, ' ; + 'uncheck to maximize in top level form', ; autosize = .t., ; value = .T., ; backstyle = 0, ; left = 30

PROCEDURE commandpreview.CLICK LOCAL foTemplate, llClosable * Create template form foTemplate = newobj('form') foTemplate.Name = SYS(2015) foTemplate.Caption = "My Report Preview Window" foTemplate.mdiform = .T.           foTemplate.top = 0 foTemplate.left = 0 * Size template form to top level form foTemplate.width = thisform.width - 8 && 8 is fudge for border foTemplate.height = thisform.height ; - 8 - sysmetric(9) && sysmetric is for TitleBar height IF !thisform.chkType.value KEYB '{ctrl+f10}' && Maximize the Preview Window ENDIF llClosable = thisform.closable thisform.closable = .f. && Make main form not closable REPORT FORM report_1 PREVIEW WINDOW (foTemplate.name) thisform.closable = llClosable  && Restore original setting ENDPROC

PROC Init DO do_menu WITH THIS,.T.,.T.        ENDPROC

ENDDEFINE

PROC do_menu && This is stripped down code from Menu Designer menu LPARAMETERS oFormRef, getMenuName, lUniquePopups LOCAL cMenuName, a_menupops

m.cMenuName = SYS(2015)

DIMENSION a_menupops[1] a_menupops[1]="_mfile"

DEFINE MENU (m.cMenuName) IN (m.oFormRef.Name) BAR DEFINE PAD _msm_file OF (m.cMenuName) PROMPT "\ Click Report Preview. Note that the preview may be maximized or minimized within the top-level form. The state of the check box determines whether the preview initially displays maximized or as a child window. When maximized, the preview resizes when the top-level form is resized. Otherwise, the preview can be sized independent of the top-level form.

