你好,欢迎访问远方教程PC版!
广告位招租
网站首页 >> 统计之窗 >> VB专区 >> 文章内容

VB应用举例14:基于VB的通用折行打印程序(第3页)

[日期:2014-12-20]   来源:远方教程  作者:VBFans   阅读:5033次[字体: ] 访问[旧版]
 捐赠远方教程 

   实例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页
图片展示
 
 
相关评论
站长推荐