请教高手打印预览的问题,还望赐教
VB6+ACCESS想问下打印报表的时候,VB6有什么好的方法可以实现打印预览?
有没第三方控件来方便的实现?
最后能详细点,举例
谢谢!!!
Public 行间距 As Long Public 上边距 As Long Public 左边距 As Long Public 下边距 As Long Public 右边距 As Long Public 行数 As Long Public 间隔 As Long '每一线在当前字段之前多少 Public 页宽 As Long Public 页高 As Long Public Sub init() '数据定义,单位为缇.如果你数据是写在设置文件里的,在这里处理,如果是A4纸,按A4纸的长宽换算为 缇 间隔 = 30 页高 = 14742 页宽 = 10206 左边距 = 1134 右边距 = 1134 上边距 = 1134 下边距 = 1134 行间距 = 250 '计算行数 行数 = (页高 - 上边距 - 下边距) / 行间距 - 2 End Sub Public Sub 打印(rs As Recordset, 标题 As String, 表格头() As String, wz() As Long, printyn As Boolean) Dim obj As Object 'Dim obj As PictureBox '写代码时用的 If printyn Then '真,打印 Set obj = Printer Else '假,模拟显示 Load 模拟显示 Set obj = 模拟显示.载入 '此函数返回一个新的 picturebox 对象 End If Dim i As Long Dim j As Long Do With obj '显示标题 i = LenB(StrConv(标题, vbFromUnicode)) .Font.Size = 12 .CurrentY = 上边距 .CurrentX = (页宽 - 左边距 - 右边距 - i * 20) / 2 obj.Print 标题 .Font.Size = 9 .Font.Bold = True For j = 0 To rs.Fields.Count - 1 .CurrentY = 3 * 行间距 + 上边距 .CurrentX = wz(j) + 间隔 + 左边距 obj.Print 表格头(j) Next j obj.Line (左边距, 3 * 行间距 + 上边距 - 间隔)-(页宽 - 右边距, 3 * 行间距 + 上边距 - 间隔) .Font.Bold = False For i = 2 To 行数 For j = 0 To rs.Fields.Count - 1 .CurrentY = (i + 2) * 行间距 + 上边距 .CurrentX = wz(j) + 间隔 + 左边距 obj.Print rs.Fields(j) Next j obj.Line (左边距, (i + 2) * 行间距 + 上边距 - 间隔)-(页宽 - 右边距, (i + 2) * 行间距 + 上边距 - 间隔) rs.MoveNext If rs.EOF Then i = i + 1 '因为用 exit for 退出循环后,i不会自动+1,所以要手动+1,为了画最后一根横线 Exit For End If Next i obj.Line (左边距, (i + 2) * 行间距 + 上边距 - 间隔)-(页宽 - 右边距, (i + 2) * 行间距 + 上边距 - 间隔) '画竖线 obj.Line (左边距, 3 * 行间距 + 上边距 - 间隔)-(左边距, (i + 2) * 行间距 + 上边距 - 间隔) For j = 1 To rs.Fields.Count - 1 'obj.Line (300, wz(j))-(300 + i * 200, wz(j)) obj.Line (wz(j) + 左边距, 3 * 行间距 + 上边距 - 间隔)-(wz(j) + 左边距, (i + 2) * 行间距 + 上边距 - 间隔) Next j obj.Line (页宽 - 右边距, 3 * 行间距 + 上边距 - 间隔)-(页宽 - 右边距, (i + 2) * 行间距 + 上边距 - 间隔) End With If Not rs.EOF Then '没有到最下页 If printyn Then '真,打印 obj.NewPage Else '假,模拟显示 Load 模拟显示 Set obj = 模拟显示.载入 End If Else If printyn Then obj.EndDoc Else 模拟显示.Show Call 模拟显示.刷新 End If Exit Do End If Loop End Sub
Option Explicit Public 页数 As Long '当前页数 Public 总页数 As Long '总页数 Private Sub Combo1_Click() Select Case Combo1.ListIndex Case 0 Picture2.Width = 页宽 / 2 Picture2.Height = 页高 / 2 Case 1 Picture2.Width = 页宽 Picture2.Height = 页高 Case 2 Picture2.Width = 页宽 * 2 Picture2.Height = 页高 * 2 End Select If Picture1.Width > Picture2.Width Then hs.Visible = False hs.Value = 0 Picture2.Left = (Picture1.Width - Picture2.Width) / 2 Else hs.Visible = True hs.Value = 0 Picture2.Left = 120 End If Call 刷新 End Sub Private Sub Command1_Click() Unload Me End Sub Private Sub Command2_Click() If 页数 > 1 Then 页数 = 页数 - 1 Call 刷新 End Sub Private Sub Command3_Click() If 页数 < 总页数 Then 页数 = 页数 + 1 Call 刷新 End Sub Private Sub Command4_Click() 页数 = 总页数 Call 刷新 End Sub Private Sub Command5_Click() 页数 = 1 Call 刷新 End Sub Private Sub Form_Load() Combo1.AddItem "50%" Combo1.AddItem "100%" Combo1.AddItem "200%" Combo1.ListIndex = 1 End Sub Private Sub Form_Resize() On Error Resume Next Picture1.Width = Me.Width - Picture1.Left - 240 Picture1.Height = Me.Height - Picture1.Top - 720 hs.Width = Picture1.Width - vs.Width hs.Top = Picture1.Height - hs.Height - 60 vs.Height = Picture1.Height - hs.Height vs.Left = Picture1.Width - vs.Width - 60 If Picture1.Width > Picture2.Width Then hs.Visible = False hs.Value = 0 Picture2.Left = (Picture1.Width - Picture2.Width) / 2 Else hs.Visible = True hs.Value = 0 Picture2.Left = 120 End If End Sub Private Sub hs_Change() If hs.Visible Then Picture2.Left = 120 - hs.Value * (Picture2.Width / 15) End If End Sub Private Sub Picture2_Paint() Call 刷新 End Sub Private Sub vs_Change() Picture2.Top = 120 - vs.Value * (Picture2.Height / 15) End Sub Public Sub 刷新() If 页数 < 1 Then 页数 = 1 If 页数 > 总页数 Then 页数 = 总页数 Picture2.PaintPicture xxx(页数).Image, 0, 0, Picture2.Width, Picture2.Height, 0, 0, 页宽, 页高 ' Picture2.PaintPicture xxx(页数).Image, 0, 0, xxx(页数).Width * bl, xxx(页数).Height * bl Label1.Caption = 页数 & " / " & 总页数 End Sub Public Function 载入() As PictureBox Dim i As Long 总页数 = 总页数 + 1 i = 总页数 Load xxx(i) xxx(i).Width = 页宽 xxx(i).Height = 页高 Set 载入 = xxx(i) End Function