gPrintListView 调用问题 高分求

chinanetspy 2007-09-04 11:50:17
网上找了一个listview 打印函数,却不知如何调用,狂汗!


请用过的朋友告诉我如何调用
我是这样调用的
gPrintListView listview,"报表头",listview

附函数:

Function gPrintListView(ByRef pobjListView As ListView, pstrHeading As String, Prn As Object) As Boolean
'--------------------------------------------------------------------------
' Name : gPrintListView
' Description : Print List View
' Parameters : Listview control, Printed page heading
' Returns : N/A
' Called From : Anywhere
' Author : Paul Jones
' Date : 07/06/2001
' Notes :
'--------------------------------------------------------------------------
Dim objCol As ColumnHeader
Dim objLI As ListItem
Dim objILS As ImageList
Dim objPic As Picture

Dim dblXScale As Double
Dim dblYScale As Double
Dim sngFontSize As Single
Dim lngX As Long
Dim lngY As Long
Dim lngX1 As Long
Dim lngY1 As Long
Dim lngX2 As Long
Dim lngRows As Long
Dim lngLeft As Long
Dim lngPageNo As Long
Dim lngEOP As Long
Dim lngEnd As Long
Dim lngWidth As Long
Dim intCols As Integer
Dim lngTop As Long
Dim intOffset As Integer
Dim px As Integer
Dim py As Integer
Dim intRowHeight As Integer
Dim strText As String
Dim strTextTrun As String

'--------------------------------------------------------------------------
'Establish print & screen metrics
'--------------------------------------------------------------------------

On Error GoTo Error_Handler

Screen.MousePointer = vbHourglass

For Each objCol In pobjListView.ColumnHeaders

lngX = lngX + objCol.Width

Next

Set objILS = pobjListView.SmallIcons

dblXScale = (Prn.Width * 0.9) / lngX
dblYScale = Prn.Height / pobjListView.Height

lngLeft = (Prn.Width - (Prn.Width * 0.95)) / 2

sngFontSize = Prn.Font.Size

If pstrHeading <> "" Then

Prn.Font.Size = 16
Prn.CurrentX = (Prn.Width / 2) - (Prn.TextWidth(pstrHeading) / 2)
'Prn.Font.Underline = True
Prn.Font.Bold = True
Prn.Print pstrHeading
Prn.Font.Underline = False
Prn.Font.Size = sngFontSize
lngTop = Prn.CurrentY + Prn.CurrentY

End If

intRowHeight = (Screen.TwipsPerPixelY * 17)

lngEOP = Prn.Height - (intRowHeight * 3)

lngX = lngLeft
lngY = lngTop

lngY1 = lngTop + (Screen.TwipsPerPixelY * 17)

Prn.CurrentY = lngY
Prn.Font.Bold = True
Prn.DrawMode = vbCopyPen

px = Screen.TwipsPerPixelX
py = Screen.TwipsPerPixelY

'--------------------------------------------------------------------------
'Print column headers with slight 3D effect
'--------------------------------------------------------------------------

For Each objCol In pobjListView.ColumnHeaders

lngX1 = lngX + (objCol.Width * dblXScale)

Prn.Line (lngX, lngY)-(lngX1, lngY1), vbButtonShadow, BF
Prn.Line (lngX, lngY)-(lngX1 - px, lngY1), RGB(245, 245, 245), BF
Prn.Line (lngX + px, lngY + py)-(lngX1, lngY1), vbButtonShadow, BF
Prn.Line (lngX + px, lngY + py)-(lngX1 - px, lngY1 - py), vbButtonFace, BF

Prn.CurrentY = lngY + ((intRowHeight - Prn.TextHeight(objCol.Text)) / 2) + py

Select Case objCol.Alignment

Case ListColumnAlignmentConstants.lvwColumnCenter

Prn.CurrentX = lngX + (((objCol.Width * dblXScale) - Prn.TextWidth(objCol.Text)) / 2)

Case ListColumnAlignmentConstants.lvwColumnLeft

Prn.CurrentX = lngX + (px * 5)

Case ListColumnAlignmentConstants.lvwColumnRight

Prn.CurrentX = lngX + ((objCol.Width * dblXScale) - Prn.TextWidth(objCol.Text)) - (px * 5)

End Select

Prn.Print objCol.Text

lngX = lngX1

Next

lngEnd = lngX1 + px

Prn.Font.Bold = False

'--------------------------------------------------------------------------
'Print list item data
'--------------------------------------------------------------------------

For Each objLI In pobjListView.ListItems

If lngY1 > lngEOP - intRowHeight - intRowHeight Then

'------------------------------------------------------------------
'Print page number
'------------------------------------------------------------------

lngPageNo = lngPageNo + 1
Prn.CurrentX = (Prn.Width / 2) - (Prn.TextWidth("第 " & lngPageNo & " 页") / 2)
Prn.CurrentY = lngEOP - intRowHeight
Prn.Print "第 " & lngPageNo & " 页" '"Page " & lngPageNo
Prn.NewPage
Prn.CurrentY = lngTop
lngY = lngTop

Else

lngY = lngY + intRowHeight

End If

lngX = lngLeft

lngY1 = lngY + intRowHeight

For Each objCol In pobjListView.ColumnHeaders

'------------------------------------------------------------------
'Print the icon if on col 1
'------------------------------------------------------------------

If objCol.Index > 1 Then

strText = objLI.SubItems(objCol.Index - 1)

intOffset = 0

Else

strText = objLI.Text

If IsEmpty(objLI.SmallIcon) Then

intOffset = 0

Else

Set objPic = objILS.Overlay(objLI.SmallIcon, objLI.SmallIcon)

Prn.PaintPicture objPic, lngX + px, lngY + (py / 2), 16 * px, 16 * py, , , , , vbSrcCopy

intOffset = px * 16

End If

End If

'------------------------------------------------------------------
'Make sure text fits
'------------------------------------------------------------------

lngWidth = (objCol.Width * dblXScale)

lngX1 = lngX + lngWidth

strTextTrun = strText

Do Until Prn.TextWidth(strTextTrun) < lngWidth - (px * 5) - intOffset Or strText = ""

strText = Left$(strText, Len(strText) - 1)

strTextTrun = strText & "..."

Loop

Prn.Line (lngX, lngY)-(lngX1, lngY1), 1, B

Prn.CurrentY = lngY + ((intRowHeight - Prn.TextHeight(strTextTrun)) / 2) + py

Select Case objCol.Alignment

Case ListColumnAlignmentConstants.lvwColumnCenter

Prn.CurrentX = lngX + intOffset + (((objCol.Width * dblXScale) - Prn.TextWidth(strTextTrun)) / 2)

Case ListColumnAlignmentConstants.lvwColumnLeft

Prn.CurrentX = lngX + intOffset + (px * 5)

Case ListColumnAlignmentConstants.lvwColumnRight

Prn.CurrentX = lngX + ((objCol.Width * dblXScale) - intOffset - Prn.TextWidth(strTextTrun)) - (px * 5)

End Select

'------------------------------------------------------------------
'Print each colum
'------------------------------------------------------------------

Prn.Print strTextTrun

lngX = lngX1

Next

Next

'--------------------------------------------------------------------------
'Print final page number
'--------------------------------------------------------------------------

lngPageNo = lngPageNo + 1

Prn.CurrentX = (Prn.Width / 2) - (Prn.TextWidth("第 " & lngPageNo & " 页") / 2)
Prn.CurrentY = lngEOP - intRowHeight
Prn.Print "第 " & lngPageNo & " 页"
Prn.EndDoc

gPrintListView = True

Screen.MousePointer = vbDefault

Set objCol = Nothing
Set objILS = Nothing
Set objLI = Nothing
Set objPic = Nothing

Exit Function

Error_Handler:

Set objCol = Nothing
Set objILS = Nothing
Set objLI = Nothing
Set objPic = Nothing

Screen.MousePointer = vbDefault

'--------------------------------------------------------------------------
'Simple error message reporting
'--------------------------------------------------------------------------

MsgBox "系统打印出错:-" & vbCrLf & vbCrLf & _
"错误号: " & Err.Number & vbCrLf & "错误内容:" & Err.Description, vbExclamation

End Function

请用过的朋友告诉我如何调用
我是这样调用的
gPrintListView listview,"报表头",listview
...全文
151 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinanetspy 2007-09-04
  • 打赏
  • 举报
回复
为什么没有人回答我啊??
chinanetspy 2007-09-04
  • 打赏
  • 举报
回复
顶啊
内容概要:本文围绕“【SCUC】N-1故障集+安全约束机组组合研究(Matlab代码实现)”展开,系统探讨电力系统在N-1故障场景下的安全约束机组组合(SCUC)问题,旨在实现系统安全性与运行经济性的协同优化。研究通过构建包含机组启停、出力计划、潮流约束、备用容量及N-1安全准则的数学模型,结合混合整数线性规划等优化算法,利用Matlab平台完成仿真解,并引入YALMIP等建模工具提升建模效率。文档提供了完整的代码实现方案与测试案例,涵盖故障集的生成与处理方法,帮助用户掌握鲁棒性和分布鲁棒优化的基本思想,适用于电力系统安全校核与调度决策支持。; 适合人群:电力系统及相关专业的研究生、从事电力调度、能源优化的科研人员及工程技术人员。; 使用场景及目标:① 掌握N-1安全准则在机组组合中的建模方法与实现流程;② 开展安全约束机组组合(SCUC)与安全约束经济调度(SCED)的仿真分析;③ 利用Matlab/YALMIP快速搭建电力系统优化模型并进行解与验证。; 阅读建议:建议读者结合文档内容与网盘提供的完整资源(含代码与数据),动手实践建模与调试过程,重点关注约束条件的设定、故障场景的枚举与处理策略,同时参考相关文献深化对鲁棒优化与分布鲁棒方法的理解。

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧