帐号: 密码:
// 设为首页 // 收藏本站 // 请您留言 // 网址导航
远方教程-满足你的求知欲!
站内搜索:
HTML ASP PHP CSS DIV Dreamweaver Photoshop Word Excel PPT SEO技巧
您当前位置:网站首页 >> 统计之窗 >> VB专区 >> 阅读文章

VB应用举例14:基于VB的通用折行打印程序

来源:远方教程 作者:VBFans 发布时间:2014-12-20 查看次数:5040 访问[新版]

   实例2:直接打印表格式窗体显示的多记录多字段,往往因某些字段的字节太多而造成纸张宽度不足。以下CmdPrnt2的Click事件中的代码,实现了对上述MSFGrid1表格记录的打印:

Private Sub CmdPrnt2_Click() 
Dim fnt As Single 
Dim pp As Integer 
Dim stry As Integer, strx As Integer 
Dim stry1 As Integer,  
strx1 As Integer, linw As Integer 
Dim page1 As Integer, p As Integer, 
 gridrow As Integer, ii As Integer 
p = 0 
ii = 1  ’ii记录MSFGRID1表格同一记录内字段最大打印行 
pp = 0 ’开始页码 
ss$ = "中国出入境检验检疫标准目录检索STEMS 2000" ’ 表头 
Static a(4) As Integer 
kan = 0 
a(2) = 1680  
a(3) = 2800 
a(4) = 5300 
page1 = 46 ’定义每页行数 
  strx = 200 
  strx1 = 200 
  stry = 1400 
  stry1 = 1400 
  linw = 240 ’定义行宽 
  fnt = 10 ’定义字体大小 
  For i = 2 To 4  
      kan = kan + a(i) 
  Next 
  gridrow = Datdatact1.Recordset.RecordCount 
  If gridrow = 0 Then 
     MsgBox "无满足条件记录打印!" 
     Exit Sub 
 End If 
  Printer.FontName = "黑体" 
  dd = prnt11(3300, 700, fnt, ss$, 26) ’打印标题 
  dd = prnt11(500, stry - 250, fnt, "标准号", 26) 
  dd = prnt11(2690, stry - 250, fnt, "标准名称", 26)  
  dd = prnt11(6690, stry - 250, fnt, "英文名称", 26)  
  Printer.Line (strx - 20, stry - 30)-(10460, stry - 30)  
  Printer.FontName = "宋体" 
  For j = 1 To gridrow  ’打印gridrow条记录 
       MSFGrid1.Row = j 
       strx = strx1 
       For i = 2 To 4 ’假设只打印2-3 列 
         MSFGrid1.Col = i 
         dd = prnt11(strx, stry, fnt, 
 MSFGrid1.Text, IIf(i = 3, 13, 55)) 
         If ii < rowlab Then  
'ii记录同一记录内字段最大打印行 
           ii = rowlab 
         End If 
         strx = strx + a(i) 
       Next 
       p = p + ii  
       rowlab = ii 
       ii = 1 ’重新初始化 
       If p > page1 Then 
           p = 0 
           strx = strx1 
           For n = 2 To 4 
             strx = strx + a(n) 
           Next 
           pp = pp + 1 
           stry = stry + rowlab * linw 
           foot$ = "第" + CStr(pp) + "页" 
           dd = prnt11(strx / 2, stry + 3 * linw, 10, foot$, 26) 
           stry = stry1 
           Printer.NewPage 
           Printer.FontName = "黑体" 
           dd = prnt11(3300, 700, fnt, ss$, 26) 
           dd = prnt11(500, stry - 250, fnt, "标准号", 26)  
           dd = prnt11(2690, stry - 250, fnt, "标准名称", 26) 
           dd = prnt11(6690, stry - 250, fnt, "英文名称", 26) 
           Printer.Line (-20, stry - 30)-(10460, stry - 30) 
           ’打印起始线 
           Printer.FontName = "宋体" 
           strx = strx1 
         Else 
           stry = stry + rowlab * linw  
         End If 
      Next 
      If p < page1 Then  
          For p = 0 To page1 + 1 
             strx = strx1 
          Next 
      End If 
      strx = strx1 
      For n = 2 To 4 
          strx = strx + a(n) 
      Next 
      pp = pp + 1 
      foot$ = "第" + CStr(pp) + "页" 
      dd = prnt11(strx / 2, stry + 3 * linw, 10, foot$, 26) 
      Printer.EndDoc 
  End Sub
第1页 第2页 第3页
感谢VBFans投稿查看TA的其他文章>>
打印 打印 | 关闭 关闭 评论
相关文章
图片新闻
站内搜索  
搜索
猜您喜欢  
最新更新  
阅读排行  
关于我们 | 联系方式 | 大事记 | 免责声明 | | 给我留言
部分广告源自金山联盟2345联盟 QQ咨询 站长之家QQ群:232617873
Copyright 2024 远方教程 © All Rights Reserved.

回顶部