vb6 打印
来源:互联网 发布:linux 查杀进程 编辑:程序博客网 时间:2024/06/07 11:46
一个简单的问题:如何在VB6里面实现打印功能?使用printer对象
A :
谁能详细一点地告诉我在VB里面怎么实现打印。另:不知道哪位大侠有相关的程序?方便的话请给我发一份让我参考参考,感激不尽!!!我的电子邮箱:dreammaker1234@sohu.com
---------------------------------------------------------------
小弟,你找我找对了,给你一段代码,自己仔细研究去吧,包你好用:
Private Sub Image5_Click() '打印报表
Dim i As Integer
Dim pageleft As Integer
Dim pageheader As Integer
Dim pagefooter As Integer
Dim pageright As Integer
Dim startx As Integer
Dim starty As Integer
Dim startline As Integer
Dim endline As Integer
Dim usewidth As Integer
Dim useheight As Integer
pageheader = 25
pagefooter = 25
pageleft = 20
pageright = 20
'定义纸张类型A4
Printer.FontSize = 20
Printer.PaperSize = 9
Printer.ScaleMode = 6
Printer.FontBold = False
Printer.ScaleLeft = -20
Printer.ScaleTop = -25
Printer.ScaleWidth = 210
Printer.ScaleHeight = 297
usewidth = Printer.ScaleWidth - 40
useheight = Printer.ScaleHeight - 50
Printer.CurrentX = 0
Printer.CurrentY = 0
Printer.DrawWidth = 2
'打印主标题
Printer.FontSize = 20
Printer.CurrentX = (usewidth - Printer.TextWidth(Me.Text1.Text & "经济情况表")) / 2
Printer.CurrentY = Printer.ScaleTop
Printer.Print Me.Text1.Text & "经济情况表"
'打印空白行
Printer.FontSize = 8
Printer.CurrentX = (usewidth - Printer.TextWidth("")) / 2
Printer.CurrentY = Printer.CurrentY + 1
Printer.Print ""
'打印副标题
Printer.FontSize = 15
Printer.CurrentX = (usewidth - Printer.TextWidth(commonth & "月份经济情况报表")) / 2
Printer.CurrentY = Printer.CurrentY + 1
Printer.Print commonth & "月份经济情况报表"
'打印空白行
Printer.FontSize = 8
Printer.CurrentX = (usewidth - Printer.TextWidth("")) / 2
Printer.CurrentY = Printer.CurrentY + 1
Printer.Print ""
'打印表的内容
'首先打印第一条横线
'打印最上边的第一条横线
Printer.CurrentX = pageleft + Printer.ScaleLeft
startline = Printer.CurrentY + 1
Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY)
Printer.FontSize = 12
Printer.CurrentY = Printer.CurrentY + 1
starty = Printer.CurrentY
Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth("")) / 2
Printer.Print ""
Printer.FontSize = 12
Printer.CurrentX = usewidth / 3 + ((usewidth / 3 - Printer.TextWidth("今年经济情况")) / 2)
Printer.CurrentY = starty
Printer.Print "今年经济情况(万元)"
Printer.FontSize = 12
Printer.CurrentX = (usewidth / 3) * 2 + ((usewidth / 3 - Printer.TextWidth("去年经济情况")) / 2)
Printer.CurrentY = starty
Printer.Print "去年经济情况(万元)"
Printer.CurrentX = pageleft + Printer.ScaleLeft
Printer.CurrentY = Printer.CurrentY + 1
Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY)
Printer.CurrentY = Printer.CurrentY + 1
For i = 0 To 10
'判断是否该页已打满
Me.MSFlexGrid1.Row = i
If Printer.CurrentY >= useheight Then
'打印横线
Printer.CurrentX = Printer.ScaleLeft + pageleft
Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY)
Printer.CurrentY = Printer.CurrentY + 1
'打印四条竖线
endline = Printer.CurrentY
Printer.Line (0, startline)-(0, endline)
Printer.Line (usewidth / 3, startline)-(usewidth / 3, endline)
Printer.Line ((usewidth / 3) * 2, startline)-((usewidth / 3) * 2, endline)
Printer.Line (usewidth, startline)-(usewidth, endline)
'打印页号
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Printer.Page)) / 3 - pageleft
Printer.CurrentY = useheight + 3
Printer.Print Printer.Page
Printer.NewPage 'NewPage告诉打印机,程序对当前输出页的发送已经结束。Printer对象应开始新的一页。
Printer.CurrentX = pageleft + Printer.ScaleLeft
Printer.CurrentY = pageheader + Printer.ScaleTop
startline = Printer.CurrentY
Else
'打印一行数据
Me.MSFlexGrid1.Col = 0
Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 8
starty = Printer.CurrentY
Printer.Print Me.MSFlexGrid1.Text
Me.MSFlexGrid1.Col = 1
Printer.CurrentX = (Printer.ScaleWidth - 40) / 3 + ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 2
Printer.CurrentY = starty
Printer.Print Me.MSFlexGrid1.Text
Me.MSFlexGrid1.Col = 2
Printer.CurrentX = ((Printer.ScaleWidth - 40) / 3) * 2 + ((Printer.ScaleWidth - 40) / 3 - Printer.TextWidth(Me.MSFlexGrid1.Text)) / 2
Printer.CurrentY = starty
Printer.Print Me.MSFlexGrid1.Text
Printer.CurrentX = pageleft + Printer.ScaleLeft
Printer.CurrentY = Printer.CurrentY + 1
Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY)
Printer.CurrentY = Printer.CurrentY + 1
End If
Next i
'打印最后一条横线
Printer.CurrentX = Printer.ScaleLeft + pageleft
Printer.Line -((Printer.ScaleLeft + Printer.ScaleWidth - pageleft), Printer.CurrentY)
endline = Printer.CurrentY
'打印四条竖线
Printer.Line (0, startline)-(0, endline)
Printer.Line (usewidth / 3, startline)-(usewidth / 3, endline)
Printer.Line ((usewidth / 3) * 2, startline)-((usewidth / 3) * 2, endline)
Printer.Line (usewidth, startline)-(usewidth, endline)
'打印页号
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth(Printer.Page)) / 3 - pageleft
Printer.CurrentY = useheight + 3
'Printer.Print Printer.Page
Printer.Print " 哈尔滨高新技术开发区"
Printer.EndDoc 'EndDoc告诉VISUAL BASIC,程序创建文档结束。VISUAL BASIC应将它发送到物理打印机上打印。
If Err.Number = 0 Then
MsgBox "you are successful!", , ""
End If
End Sub
- vb6 打印
- VB6 shell 打印
- VB6 DataReport打印自定义纸张
- VB6.0 直接打印 PDF
- vb6
- vb6
- VB6
- vb6 如何保存图片,mschart如何打印图片
- C#,VB.Net,VB6调用Codesoft打印标签
- vb6设置打印机纸张类型,以及打印方向
- VB6 调取EXCEL 打印时指定 打印范围和打印份数
- 重用VB6
- VB6真好用
- VB6.0
- 【VB6】VB6类库项目中的MTSTransactionMode
- 【VB6】VB6类库项目中的Persistable
- 打印
- 打印
- JSTL标签库学习总结
- const关键字在类的成员函数上的应用(1)
- linux Shell: 定时清理指定目录下大于指定大小、指定文件名的文件?
- 前台调用后台方法
- JSTL标签库学习总结
- vb6 打印
- DataSnap与JSON序列化(4)
- const关键字在类的成员函数上的应用(2)
- Linux内核源代码中的Makefile分析
- HtmlParser初步研究(转帖加其他参考理解)
- 高性能WEB开发(6) - web性能测试工具推荐
- 视频去交错:基于模糊控制的运动自适应算法(GPU实现)
- Linux内核Makefile编译生成内核目标文件的过程
- jqgrid中文属性方法大全