在 Visual FoxPro 9.0 中阻止从报表预览打印
本文介绍如何禁用在 Visual FoxPro 9.0 中使用 Object-Assisted Reporting 预览报表时打印报表的选项。
原始产品版本: Visual FoxPro
原始 KB 编号: 895279
摘要
Microsoft Visual FoxPro 9.0 引入了 Object-Assisted Reporting 体系结构。 通过这种新设计,可以直接通过 Visual FoxPro 9.0 报告工具(如报表设计器和报表预览)通过代码进行交互。 因此,在 Visual FoxPro 9.0 中禁用从报表预览打印的功能比在早期版本的 Visual FoxPro 中更容易。 本文介绍如何编写代码来直接与报表预览交互,以及如何配置 Object-Assisted 报表预览。
更多信息
默认情况下,在 Visual FoxPro 9.0 中预览 Object-Assisted 报表时,用户可以使用以下方法之一从“报表预览”窗口打印报表:
- 在“报表预览”工具栏上,单击“ 打印 ”按钮。
- 在“报表预览”窗口中右键单击,然后单击“ 打印”。
你可能想要禁用此选项。 在 Visual FoxPro 的早期版本中,必须更改 Visual FoxPro 资源文件 (FoxUser.dbf) 。
在 Visual FoxPro 9.0 中,仍可以更改 FoxUser.dbf 文件,以禁用报表预览窗口中的打印。 但是,随着 Object-Assisted Reporting 的引入,现在提供了一种替代方法。 默认情况下,Visual FoxPro 9.0 中的 Object-Assisted 报告未启用。 若要启用它,必须更改设置 REPORTBEHAVIOR
。 为此,请使用以下方法之一:
方法 1,通过 Visual FoxPro IDE 更改报表引擎行为设置:
- 在“工具”菜单上,单击“选项”。
- 在“选项”对话框中,单击“报表”选项卡,然后在“报表引擎”行为列表中选择“90 (对象辅助) ”。
- (可选) 如果希望此设置在 Visual FoxPro 9.0 会话之间保留,请在“选项”对话框中单击“设置为默认值”。
方法 2,在代码中运行以下命令以启用 Object-Assisted 报告:
SET REPORTBEHAVIOR 90
.
代码示例
运行以下代码示例时,将预览名为 Colors.frx 的示例报表文件。 该代码示例预览报表,并使用预览容器中的属性设置和预览扩展处理程序的组合,以从报表预览窗口完全禁用打印。
此代码示例还解决了 Visual FoxPro 9.0 Object-Assisted 报表预览中存在的问题,即报表预览工具栏无法正确保留同一报表预览会话中不同外观之间的显示设置。
此代码示例既适用于 Visual FoxPro 9.0 开发环境,也适用于使用 Visual FoxPro 9.0 创建的可执行文件,只要使用 Object-Assisted Reporting 即可。
若要使用此代码示例,请执行以下步骤:
将以下代码保存到 Visual FoxPro 9.0 中的新程序文件,然后运行代码。
*----------- START CODE * *----------------------------------- * AUTHOR: Trevor Hancock * CREATED: 02/24/05 02:47:08 PM * ABSTRACT: * Shows how to disable printing from * PREVIEW when you use object-assisted * reporting in VFP9. * * Also includes a workaround for problem * where the PREVIEW toolbar does not * recognize the TextOnToolbar or * PrintFromPreview settings between * toolbar displays during same preview. *----------------------------------- *-- Defines whether to alllow for *-- printing during preview. Used to set *-- the "AllowPrintfromPreview" property *-- of the object-assisted preview container *-- later in this code. #DEFINE PrintFromPreview .T. LOCAL loPreviewContainer AS FORM, ; loReportListener AS REPORTLISTENER, ; loExHandler AS ExtensionHandler OF SYS(16) *-- Get a preview container from the *-- .APP registered to handle object-assisted *-- report previewing. loPreviewContainer = NULL DO (_REPORTPREVIEW) WITH loPreviewContainer *-- Create a PREVIEW listener loReportListener = NEWOBJECT('ReportListener') loReportListener.LISTENERTYPE = 1 &&Preview *-- Link the Listener and preview container loReportListener.PREVIEWCONTAINER = loPreviewContainer *-- Changing this property prevents printing from the Preview toolbar *-- and from right-clicking on the preview container, and then clicking "print". *-- This property is not in the VFP9 documentation at this point. loPreviewContainer.AllowPrintfromPreview = PrintFromPreview *-- Controls appearance of text on some of the *-- Preview toolbar buttons. .F. is the default. *-- Included here just to show that it is an available option. loPreviewContainer.TextOnToolbar = .F. *-- Create an extension handler and hook it to the *-- preview container. This will let you manipulate *-- properties of the container and its Preview toolbar loExHandler = NEWOBJECT('ExtensionHandler') loPreviewContainer.SetExtensionHandler( loExHandler ) REPORT FORM ; HOME() + 'Samples\Solution\Reports\colors.frx' ; OBJECT loReportListener RELEASE loPreviewContainer, loReportListener, loExHandler *------------------------- *------------------------- DEFINE CLASS ExtensionHandler AS CUSTOM *-- Ref to the Preview Container's Preview Form PreviewForm = NULL *-- Here you implement (hook into) the PreviewForm_Assign *-- event of the preview container's parent proxy PROCEDURE PreviewForm_Assign( loRef ) *-- Perform default behavior: assign obj ref. THIS.PreviewForm = loRef *-- Grab the obj ref to the preview form and bind to its *-- ShowToolbar() method. This lets the *-- STB_Handler() method of this extension handler *-- to run code whenever the Preview toolbar is shown *-- by the PreviewForm.ShowToolbar() method. IF !ISNULL( loRef ) BINDEVENT(THIS.PreviewForm, ; 'ShowToolbar', THIS, 'STB_Handler') ENDIF ENDPROC PROCEDURE STB_Handler(lEnabled) *-- Here you work around the setting *-- persistence problem in the Preview toolbar. *-- The Preview toolbar class (frxpreviewtoolbar) *-- already has code that you can use to enforce *-- setting's persistence; it is just not called. Here, *-- you call it. WITH THIS.PreviewForm.TOOLBAR .REFRESH() *-- When you call frxpreviewtoolbar::REFRESH(), the *-- toolbar caption is set to its Preview form, *-- which differs from typical behavior. You must revert that *-- to be consistent. If you did not do this, *-- you would see " - Page 2" appended to the toolbar *-- caption if you skipped pages. .CAPTION = THIS.PreviewForm.formCaption ENDWITH ENDPROC *-- A preview container requires these methods *-- to be implemented in an associated preview extension handler. *-- They are not used in this example, but still must be here. PROCEDURE AddBarsToMenu( cPopup, iNextBar ) PROCEDURE SHOW( iStyle ) ENDPROC PROCEDURE HandledKeyPress( nKeyCode, nShiftAltCtrl ) RETURN .F. ENDPROC PROCEDURE PAINT ENDPROC PROCEDURE RELEASE RETURN .T. ENDPROC ENDDEFINE * * *----------- END CODE
将打开 Colors.frx 报表的预览。
注意
可以通过右键单击预览或单击“报表预览”工具栏上的“ 打印 ”,从“报表预览”窗口打印。
关闭预览,然后在程序编辑器中修改代码。
将代码顶部的 #DEFINE 语句更改为 .F 值。 为此,请找到以下代码。
#DEFINE PrintFromPreview .T.
将它替换为以下代码:
#DEFINE PrintFromPreview .F.
保存代码,然后再次运行。
注意
现在,通过右键单击预览或单击报表预览工具栏上的“ 打印 ”,无法从“报表预览”窗口打印。