根据设置的参数设置报表使用的纸张、反向、边距、以及报表是否居中显示的解决代码
转载请注明出处
Private Function SetReportOPtion(ByRef CustomReport As ReportDocument, ByVal sName As String, ByRef PaperType As RepOption) As Boolean
Dim Txt As String
Try
PaperType = getPaper(sName)
Dim TotalWid As Integer = GetTotalWid(sName) '这个总宽度应该是各字段的宽度总和
If (TotalWid + 1000) > PaperType.Wid Then '报表的边距+报表的 总宽度是否 超过纸张的总宽度
MsgBox("报表宽度大于纸张,没法显示", MsgBoxStyle.Critical, "") '
Return False
End If
Dim printOpt As CrystalDecisions.CrystalReports.Engine.PrintOptions = CustomReport.PrintOptions
printOpt.PaperOrientation = PaperType.PaperOrigin '方向
printOpt.PaperSize = PaperType.Paper '纸张
Txt = GetINI("Report", "AutoCenter", "0", sName)
'------------------------边距
Dim Margen As CrystalDecisions.Shared.PageMargins
If Txt = "1" Then
Margen.leftMargin = (PaperType.Wid - TotalWid) / 2
Margen.rightMargin = (PaperType.Wid - TotalWid) / 2
Else
Txt = GetINI("Report", "leftMargin", "1440", sName)
Margen.leftMargin = Txt
TotalWid = TotalWid - Txt
Txt = GetINI("Report", "rightMargin", "1440", sName)
Margen.rightMargin = Txt
End If
Txt = GetINI("Report", "topMargin", "1440", sName)
Margen.topMargin = Txt
Txt = GetINI("Report", "bottomMargin", "1440", sName)
Margen.bottomMargin = Txt
TotalWid = TotalWid - Txt
printOpt.ApplyPageMargins(Margen)
Catch
MsgBox(Err.Description, MsgBoxStyle.Critical, "")
Return False
End Try
Return True
End Function