本帖最后由 foxtable 于 2016-3-19 14:40 编辑
因为单据是横向的,宽度大于高度,所以AutoRotate属性需要设置为False。
我做了一个打印按钮,按钮的代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim doc As New C1.C1Preview.C1PrintDocument
doc.DefaultUnit = C1.C1Preview.UnitTypeEnum.Mm
doc.PageLayout.PageSettings.Width = 150
doc.PageLayout.PageSettings.Height = 80
doc.PageLayout.PageSettings.TopMargin = 10
doc.PageLayout.PageSettings.LeftMargin = 10
doc.PageLayout.PageSettings.RightMargin = 10
doc.PageLayout.PageSettings.BottomMargin = 10
Dim ra As New C1.C1Preview.RenderArea()
ra.Width = "130"
ra.Height = "60"
ra.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red)
doc.Body.Children.Add(ra)
Dim pm As New C1.C1Preview.C1PrintManager
pm.PrintOptions.AutoRotate = False '禁止自动旋转
pm.PrintOptions.CenterPage = False
pm.PrintOptions.PageScaling = C1.C1Preview.PageScalingEnum.None
pm.Document = doc
doc.Generate()
Dim ps As System.Drawing.Printing.PrinterSettings = doc.PageLayout.PageSettings.ToPageSettings.PrinterSettings
pm.Print(ps)
End Sub
得到的打印效果如下,是符合我的预期的:
接着我做了一个预览按钮,预览按钮的代码如下:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim doc As New C1.C1Preview.C1PrintDocument
doc.DefaultUnit = C1.C1Preview.UnitTypeEnum.Mm
doc.PageLayout.PageSettings.Width = 150
doc.PageLayout.PageSettings.Height = 80
doc.PageLayout.PageSettings.TopMargin = 10
doc.PageLayout.PageSettings.LeftMargin = 10
doc.PageLayout.PageSettings.RightMargin = 10
doc.PageLayout.PageSettings.BottomMargin = 10
Dim ra As New C1.C1Preview.RenderArea()
ra.Width = "130"
ra.Height = "60"
ra.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red)
doc.Body.Children.Add(ra)
Dim dlg As New C1.Win.C1Preview.C1PrintPreviewDialog
dlg.PreviewPane.PageSettings = doc.PageLayout.PageSettings.ToPageSettings
With dlg.PreviewPane.PrintOptions
.AutoRotate = False '静止自动旋转
.CenterPage = False
.PageScaling = C1.C1Preview.PageScalingEnum.None
End With
dlg.Document = doc
dlg.ShowDialog()
End Sub
单击这个按钮,出现打印预览窗口,在窗口单击打印按钮,得到的打印结果如下:
显然这个这个结果是不对的,我希望是横向,这里变成了纵向,AutoRotate属性在这里似乎没有生效,为什么几乎同样的代码得到的打印结果不一样呢。
然后我将删除 “.AutoRotate = False '静止自动旋转”,将打印预览按钮改为:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim doc As New C1.C1Preview.C1PrintDocument
doc.DefaultUnit = C1.C1Preview.UnitTypeEnum.Mm
doc.PageLayout.PageSettings.Width = 150
doc.PageLayout.PageSettings.Height = 80
doc.PageLayout.PageSettings.TopMargin = 10
doc.PageLayout.PageSettings.LeftMargin = 10
doc.PageLayout.PageSettings.RightMargin = 10
doc.PageLayout.PageSettings.BottomMargin = 10
Dim ra As New C1.C1Preview.RenderArea()
ra.Width = "130"
ra.Height = "60"
ra.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red)
doc.Body.Children.Add(ra)
Dim dlg As New C1.Win.C1Preview.C1PrintPreviewDialog
dlg.PreviewPane.PageSettings = doc.PageLayout.PageSettings.ToPageSettings
With dlg.PreviewPane.PrintOptions
.CenterPage = False
.PageScaling = C1.C1Preview.PageScalingEnum.None
End With
dlg.Document = doc
dlg.ShowDialog()
End Sub
单击这个按钮,出现打印预览窗口,在窗口单击打印按钮,得到的打印结果如下:
我的问题是:
1、怎样才能在预览窗口打印的时候,得到的结果能够和直接打印一致?
2、AutoRotate属性在直接打印和打印预览的时候,效果似乎是相反的。
|