How to show a Print Preview window as MDI child of Top-Level form (190069)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 6.0
  • Microsoft Visual FoxPro for Windows 7.0
  • Microsoft Visual FoxPro 8.0
  • 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).

  1. 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 "\<File"
             ON PAD _msm_file OF (m.cMenuName) ACTIVATE POPUP (a_menupops[1])
             DEFINE POPUP (a_menupops[1]) MARGIN RELATIVE SHADOW COLOR SCHEME 4
             DEFINE BAR 1 OF (a_menupops[1]) PROMPT "C\<lose" ;
                SKIP FOR WEXIST("My Report Preview Window")
             ON SELECTION BAR 1 of (a_menupops[1]) _screen.activeform.release()
             Activate MENU (m.cMenuName) NOWAIT
          ENDPROC
    						
  2. 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.

REFERENCES

For more information about displaying report previews in top-level forms in Visual FoxPro 6.0, and using the new REPORT FORM ... IN WINDOW syntax, please see the following article in the Microsoft Knowledge Base:

188887 HOWTO: How to Display Print Preview in a Top-Level Form

For information about using the Visual FoxPro desktop to display report previews from top-level forms in Visual FoxPro 5.0, please see the following article in the Microsoft Knowledge Base:

156237 PRB: Report Designer/Preview Needs VFP Desktop to Display

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Jim Saunders, Microsoft Corporation

Modification Type:MajorLast Reviewed:2/11/2005
Keywords:kbhowto KB190069