| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4397 人关注过本帖
标题:VB里面怎么实现打印功能
只看楼主 加入收藏
hsbwp1314
Rank: 2
来 自:湖南长沙
等 级:论坛游民
帖 子:88
专家分:25
注 册:2008-12-1
结帖率:53.85%
收藏
已结贴  问题点数:2 回复次数:5 
VB里面怎么实现打印功能
           VB里面怎么实现打印功能。怎么实现预览,能按要求规格调整样式。怎么样按自己设置的格式打出来
搜索更多相关主题的帖子: 规格 
2011-07-01 17:31
W11400661
Rank: 8Rank: 8
来 自:达拉达斯
等 级:蝙蝠侠
威 望:2
帖 子:163
专家分:834
注 册:2008-10-12
收藏
得分:0 
DataReport
你还是自己研究吧
啥都不可能是现成的
2011-07-01 19:06
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
以下是引用W11400661在2011-7-1 19:06:44的发言:

DataReport
你还是自己研究吧
啥都不可能是现成的      
     

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2011-07-01 19:11
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:2 
http://topic.

程序代码:
Private Sub cmdCommand1_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

不要選我當版主
2011-07-01 20:13
adffdda
Rank: 2
等 级:论坛游民
帖 子:98
专家分:15
注 册:2015-1-6
收藏
得分:0 
谢谢分享!!
2016-03-26 10:09
dsasada
Rank: 1
等 级:新手上路
帖 子:54
专家分:3
注 册:2018-3-30
收藏
得分:0 
Option Explicit
    Dim X As Long
    Dim y As Long
    Dim fnt As Variant
    Dim txt As String
    Dim dy As Variant
     
Public Function prnt(X As Variant, y As Variant, fnt As Variant, txt As Variant)
    Printer.CurrentX = X
    Printer.CurrentY = y
    Printer.FontSize = fnt
    Printer.Print txt
End Function
 
Private Sub Command1_Click()
    Printer.ScaleMode = 6 '以mm定位
    Printer.CurrentX = 10
    Printer.CurrentY = 20
    fnt = 12
    txt = "YD(0)"
    dy = prnt(X, y, fnt, txt)
    Printer.EndDoc
End Sub

[此贴子已经被作者于2018-4-17 14:25编辑过]

2018-04-17 14:21
快速回复:VB里面怎么实现打印功能
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031683 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved