在窗体中实现打印预览功能,实现以下非规范表格和数据 的打印

1.第一行线的宽度是2,其他线条的宽度为1,并且表格的中间有虚线,表格右边不封口;2.编写函数实现所有的打印功能,以便在窗体中进行打印的功能同样可以用到打印机上,3。打印... 1.第一行线的宽度是2,其他线条的宽度为1,并且表格的中间有虚线,表格右边不封口;
2.编写函数实现所有的打印功能,以便在窗体中进行打印的功能同样可以用到打印机上,
3。打印预览窗口背景色为白色,无标题栏。缺省最大化显示
4.在打印预览窗口按任意键或者点任意处,关闭该窗口
展开
 我来答
zdingyun
2006-02-23 · 知道合伙人软件行家
zdingyun
知道合伙人软件行家
采纳数:15429 获赞数:48174
1982年上海业余工业大学化工系毕业 现退休

向TA提问 私信TA
展开全部
VB下数据报表打印输出方法有多种,一是通过自己的设计和编程完成报表打印输出。二是通过MS OFFICE实现报表打印输出。三是应用数据报表设计器的报表打印输出。本人经常使用第一种方法,它具有根据需要灵活应用的特点,但需编写程序。下附代码,第一段代码定义基本变量,第二段代码定义打印函数,第三段代码是具体打印代码,含数据转换。第四段代码是窗体加载代码,具体连接数据库和打印代码根据你所涉及的数据要求进行修改。预览代码在如下网址:
http://zhidao.baidu.com/question/4165080.html
报表打印代码:
Option Explicit
Private n As Integer
Private m As Integer
Private zh_dm(10) As Double
Private dy_dm(3000, 10) As Variant
Private zsl As Integer
Private y As Integer
Private x As Integer
Private i As Integer
Private k As Integer
Private p As Integer
Private pa As Integer
Private j As Integer
Private txt As String
Private fnt As Integer
Private dd As Variant

Public Function prnt(x As Variant, y As Variant, fnt As Variant, txt0 As Variant)
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = fnt
Printer.Print txt0
End Function

Private Sub cmdPrint_Click()
Adodc1.Recordset.MoveFirst
For i = 0 To zsl - 1
For j = 0 To 7
dy_dm(i, j) = Adodc1.Recordset(j)
Next j
Adodc1.Recordset.MoveNext
Next i
'确定页数
k = Int(zsl / 80)'80为每页行数
If k - zsl / 80 < 0 Then
k = k + 1
End If

fnt = 8
For p = 0 To k - 1
pa = p + 1
y = 300
x = 4500
txt = "机物料库存"
dd = prnt(x, y, fnt, txt)
x = 8500
txt = "第" & p + 1 & "页"
dd = prnt(x, y, fnt, txt)
y = 500
x = 600
txt = "备件代码"
dd = prnt(x, y, fnt, txt)
x = 1500
txt = "备件名称"
dd = prnt(x, y, fnt, txt)
x = 3500
txt = "备件规格"
dd = prnt(x, y, fnt, txt)
x = 5500
txt = "进口计算机号"
dd = prnt(x, y, fnt, txt)
x = 7500
txt = "最低储备量"
dd = prnt(x, y, fnt, txt)
x = 9000
txt = "库存量"
dd = prnt(x, y, fnt, txt)

For i = 0 + p * 80 To 79 + p * 80
y = 700 + 180 * (i - p * 80)
x = 600
txt = dy_dm(i, 1)
dd = prnt(x, y, fnt, txt)
x = 1500
txt = dy_dm(i, 2)
dd = prnt(x, y, fnt, txt)
x = 3500
txt = dy_dm(i, 3)
dd = prnt(x, y, fnt, txt)
x = 5500
txt = dy_dm(i, 4)
dd = prnt(x, y, fnt, txt)
x = 7500
txt = dy_dm(i, 5)
dd = prnt(x, y, fnt, txt)
x = 9000
txt = dy_dm(i, 6)
dd = prnt(x, y, fnt, txt)
If Int(i / 10) - i / 10 = 0 Then
Printer.Line (500, 695 + (i - p * 80) * 180)-(10000, 695 + (i - p * 80) * 180)
End If
Next i
If zsl - p * 80 > 80 Then
Printer.Line (500, 695 + 180 * 80)-(10000, 695 + 180 * 80)
Printer.NewPage
End If
Next p
Printer.EndDoc ' 打印完成。
Cls
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc1.RecordSource = "select cs.js_dm,cs.备件代码,cs.备件名称,cs.备件规格,cs.进口计算机号,cs.最低库存量,sl.结存数量,sl.结存金额,sl.结存单价,sl.类别代码 from JWCK_BM as cs,jwl_jiec as sl" & _
" where cs.备件代码 = sl.备件代码" & " and cs.备件代码>" & "''" & " order by sl.类别代码,sl.备件代码"
Adodc1.Refresh
DataGrid1.Refresh
zsl = Adodc1.Recordset.RecordCount
Adodc3.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=jwl_dbf"
Adodc3.RecordSource = "select sum(结存金额) as hj from jwl_jiec"
Adodc3.Refresh
End Sub

以上供参考。其它请参考西安交通大学出版社出版的“VISUAL BASIC 6.0 高级编程技巧-ADO数据访问篇“
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式