VF9实现滚动式打印预览程序Word格式.docx
- 文档编号:6916454
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:27
- 大小:22.37KB
VF9实现滚动式打印预览程序Word格式.docx
《VF9实现滚动式打印预览程序Word格式.docx》由会员分享,可在线阅读,更多相关《VF9实现滚动式打印预览程序Word格式.docx(27页珍藏版)》请在冰点文库上搜索。
ReportForm(RptName)
ObjectoListenerNowait&
FOR&
rptfor=&
rptforval
*--报表预览窗
DefineClassReportFormAsForm
caption="
打印预览"
AutoCenter=.T.
WindowState=2
BorderStyle=0
TitleBar=0
WindowType=1
BackColor=Rgb(65,65,65)
showwindow=1
DataSession=1
oListener=.Null.
nCurrentPage=1
nPageHeight=100
nPageWidth=100
ScrollBars=3
vscrollsmallchange=10
AllowOutput=.F.
oTools=.Null.
oGotoPage=
.Null.
oPrint=
*printbl=0
oshpPreview=.null.
AddObjectshpPreview1
AsmyPreview
With;
Top=10,;
Left=10,;
Width=
300,;
Height=
300
ProcedureInit
*-隐藏顶层表单的工具栏(可根据需要选用)
IFotoolbarbl=.t.&
当otoolbarbl为真时(otoolbarbl全局变量返回工具栏的显示与否)
HIDEWINDOW常用&
隐藏名为“常用”的工具栏
SETMARKOFBAR2OF显示vTO.f.&
去除“显示V”菜单中菜单编号为2的菜单项(用于显示或隐藏工具栏)前的勾
otoolbarbl=.f.
ENDIF
******************************************
DoDefault()
WithThisAsForm
.oTools=Createobject([frxpreviewtoolbar])
.oGotoPage
=Createobject([frxgotopageform])
.oPrint
=Createobject([frxPrintForm])
.oshpPreview=CREATEOBJECT([myPreview])
With.oTools
.Show()
Bindevent(This.oTools,[CboZooMInteractiveChange],This,[CboZooMInteractiveChange])
Bindevent(.cmdClose,[Click],This,[cmdCloseClick])
Bindevent(.cmdgotopage,[Click],This,[ActionGotoPage])
Bindevent(.cmdprint,[Click],This,[print])
Endwith
.Refresh
Endproc
ProcedureSetReport
LparametersoListenerRef
This.oListener=oListenerRef
&
将对ReportListener对象的引用保存到表单的oListener属性中
ProcedureShow
LparametersnStyle
printshowbl=.t.
WithThis
IfVartype(.oListener)="
O"
.nPageHeight=.oListener.GetPageHeight()/10
获得页面的像素高度(每英寸96DPI)
.nPageWidth=.oListener.GetPageWidth()/10
获得页面的像素宽度
.shpPreview1.Height=Int(.nPageHeight)
设置形状的高度
.shpPreview1.Width=Int(.nPageWidth)
设置形状的宽度
.Caption="
标题中包含有报表的文件名称
.shpPreview1.left=(_screen.activeform.width-.shpPreview1.Width)/2&
根据当前窗口的大小,设置第一页的左边距
*-根据报表的页数添加预览页面
IF.oListener.OutputPageCount>
.VScrollSmallChange=200
FORi=2TO.oListener.OutputPageCount
shpbl="
shpPreview"
+ALLTRIM(STR(i))
.addobject("
shpbl"
"
myPreview"
.&
shpbl..visible=.t.
shpbl..left=.shpPreview1.left
shpbl..height=INT(.nPageHeight)
shpbl..width=INT(.npagewidth)
shpbl..top=10+(INT(.npageheight)+5)*(i-1)
IF.shpPreview1.left<
shpbl..left=0
ENDFOR
+ALLTRIM(STR(.oListener.OutputPageCount))
endtop=.&
shpbl..top
.shpPreview1.left=0
Endif
DoDefault(nStyle)
执行默认的Show方法行为
ENDPROC
PROCEDUREscrolled
LPARAMETERSnDirection,nShift,nXCoord,nYCoord
WITHthis
IFendtop+.shpPreview1.height-32765>
IF(nDirection=1ORnDirection=3)AND.&
shpbl..top+.shpPreview1.height>
32765
.shpPreview1.top=.shpPreview1.top-INT(endtop+.shpPreview1.height-32765)/157-1-10
FORj1=2TO.oListener.OutputPageCount
+ALLTRIM(STR(j1))
shpbl..top=.shpPreview1.top+(.shpPreview1.height+5)*(j1-1)
shpbl..width=.shpPreview1.width
shpbl..height=.shpPreview1.height
ENDIF
IF(nDirection=0ORnDirection=2)AND.shpPreview1.top<
10
.shpPreview1.top=.shpPreview1.top+INT((endtop+.shpPreview1.height-32765)/157)+1+10
IF.shpPreview1.top>
10
.shpPreview1.top=10
FORj2=2TO.oListener.OutputPageCount
+ALLTRIM(STR(j2))
shpbl..top=.shpPreview1.top+(.shpPreview1.height+5)*(j2-1)
FORj3=1TO.oListener.OutPutPageCount
+ALLTRIM(STR(j3))
IF.&
shpbl..top<
.viewporttop+INT(SYSMETRIC
(2)*0.5)AND.&
shpbl..top+.nPageHeight>
.viewporttop+INT(SYSMETRIC
(2)*0.5)
.nCurrentPage=j3
endfor
ENDWITH
ENDPROC
ProcedurePaint
IfVartype(.oListener)="
.oListener.OutputPage(1,.shpPreview1,2)
1
FORi1=2TO.oListener.OutputPageCount
+ALLTRIM(STR(i1))
.oListener.OutputPage(i1,.&
shpbl,2)
.CmdRefresh()
PROCEDUREunload
*-工具栏显示(可选)
IFotoolbarbl=.f.andotoolbargb=.f.&
在工具栏未显示并且没有关闭的情况下(全局变量otoolbargb用于工具栏是否关闭)
showWINDOW常用&
隐藏“常用”工具栏
SETMARKOFBAR2OF显示vTO.t.&
显示“显示v”菜单中菜单编号为2的菜单项前的勾
otoolbarbl=.t.
********************
printshowbl=.f.&
返回预览窗口关闭(printshowbl为全局变量,可选)
endproc
ProcedureCMDRefresh
ProcedureQueryUnload
IfVartype(This.oListener)='
O'
.oListener.PreviewContainer=.Null.
释放对报表预览程序对象的引用
.oListener.OnPreviewClose(.F.)
关闭预览
.oListener=.Null.
*--指定页
ProcedureActionGotoPage
WithThisform
.oTools.Enabled=.F.
.oGoToPage.PageNo=.nCurrentPage
.oGoToPage.PageTotal
=.oListener.OutputPageCount
.oGotoPage.Show()
If.oGoToPage.PageNo>
=1And.oGoToPage.PageNo<
=.oListener.OutputPageCount
.nCurrentPage=.oGoToPage.PageNo
+ALLTRIM(STR(.nCurrentPage))
shpbl..top>
upbl=.&
shpbl..top-32765+.shpPreview1.height
FORi=1TO.oListener.OutputPageCount
shpbl..top=.&
shpbl..top-upbl
downbl=-.&
shpbl..top+10
shpbl..top+downbl
.SetViewPort(.ViewPortLeft,.&
shpbl..top-5)
Thisform.CMDRefresh
Else
.oTools.Enabled=.T.
*--关闭按扭
ProcedurecmdCloseClick
IfVartype(.oListener)='
.oListener.PreviewContainer=.Null.
.oListener.OnPreviewClose(.F.)
.Release()
printshowbl=.f.
*--更改显示比例
ProcedureCboZooMInteractiveChange
LparametersvVal
.shpPreview1.Height=Int(.nPageHeight*Val(vVal)/100)
.shpPreview1.Width=Int(.nPageWidth*Val(vVal)/100)
.oListener.OutputPage(1,.shpPreview1,2)
.shpPreview1.left=(_screen.activeform.width-.shpPreview1.Width)/2
FORi2=2TO.oListener.OutputPageCount
+ALLTRIM(STR(i2))
shpbl..top=.shpPreview1.top+(.shpPreview1.height+5)*(i2-1)
.oListener.OutputPage(i2,.&
.viewporttop+INT(SYSMETRIC
(2)*0.6)AND.&
.viewporttop+INT(SYSMETRIC
(2)*0.6)
.nCurrentPage=i2
*--打印
ProcedurePrint
.oPrint.PageNo=.nCurrentPage
.oPrint.PageTotal
.oPrint.Show()
If.oPrint.PrintOk=.T.
DoCase
*--打印所有的页
Case.oPrint.opgPrint.Value=1
打印所有页
.oListener.CommandClauses.PrintRangeFrom=1
.oListener.CommandClauses.PrintRangeTo=.oListener.OutputPageCount
prt1=1
prt2=.oListener.OutputPageCount
*--打印当前页
Case.oPrint.opgPrint.Value=2
.oListener.CommandClauses.PrintRangeFrom=
.nCurrentPage
.oListener.CommandClauses.PrintRangeTo
=.nCurrentPage
prt1=.nCurrentPage
prt2=.nCurrentPage
*--打印页码范围
Case.oPrint.opgPrint.Value=3
.oListener.CommandClauses.PrintRangeFrom=.oPrint.spnPageNoFrom.Value
.oListener.CommandClauses.PrintRangeTo=.oPrint.spnPageNoTo.Value
prt1=.oPrint.spnPageNoFrom.Value
prt2=.oPrint.spnPageNoTo.Value
ENDCASE
IF.oPrint.prtfile.value=.f.
WAITWINDOW[请稍候,系统正在进行打印处理......]NOWAIT
SETPRINTERTONAME"
oCurPrinter"
REPORTFORM(RptName)RANGEprt1,prt2TOPRINTERnodialog
.oListener.CommandClauses.OutPutTo=1
设置输出到打印机
ELSE
WAITWINDOW[系统正准备进行打印处理......]NOWAIT
*pbl=prt1
*recobl=prt2
.oListener.listenertype=1
DOtiffile
Enddefine
DefineClassCommandButtonAsCommandButton
Height=22
Width=23
Top=0
SpecialEffect=2
Caption=[]
DefineClassBaseReportListenerAsReportListener
ListenerType=1
设置输出模式
OutputType=1&
输出类型
DynamicLineHeight=.F.
tifffilename="
DefineClassRe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VF9 实现 滚动式 打印 预览 程序