请教关于vb.net打印的问题
最近正在学习vb.net,试着写了一个打印练习程序,如下:
Public Class printcontrol
Private conn As String = "Provider=SQLOLEDB.1;Password=810628;Persist Security Info=True;User ID=sa;Initial Catalog=成本核算;Data Source=caiwu11\FINANCE"
Private rowPage As Integer = 0
Private Sub PrintDocument1_PrintPage1(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim startX As Integer = 150, startY As Integer = 120
Dim strSql As String = "select top 40 款号,成本,数量,类型 from 成本表 "
Dim tb As DataTable = DbOperation.DBOperate(strSql, conn)
Dim dbRow As DataRow
Dim rowCount As Integer
Dim rowsInperpage As Integer = 18
Dim fontBold As New Font("宋体", 15, FontStyle.Bold)
Dim r As Integer = tb.Rows.Count
e.Graphics.DrawString("款号", fontBold, Brushes.Black, startX, startY)
e.Graphics.DrawString("成本", fontBold, Brushes.Black, startX + 150, startY)
e.Graphics.DrawString("数量", New Font("宋体", 15, FontStyle.Bold), Brushes.Black, startX + 300, startY)
e.Graphics.DrawString("类型", New Font("宋体", 15, FontStyle.Bold), Brushes.Black, startX + 450, startY)
startY = startY + 50
For rowCount = rowPage * rowsInperpage To IIf((rowPage + 1) * rowsInperpage > (r - 1), (r - 1), (rowPage + 1) * rowsInperpage)
dbRow = tb.Rows(rowCount)
e.Graphics.DrawString(tb.Rows(rowCount)("款号"), New Font("宋体", 10), Brushes.Black, startX, startY)
e.Graphics.DrawString(tb.Rows(rowCount)("成本"), New Font("宋体", 10), Brushes.Black, startX + 150, startY)
e.Graphics.DrawString(tb.Rows(rowCount)("数量"), New Font("宋体", 10), Brushes.Black, startX + 300, startY)
e.Graphics.DrawString(tb.Rows(rowCount)("类型"), New Font("宋体", 10), Brushes.Black, startX + 450, startY)
startY = startY + 50
Next
rowPage += 1
If r > rowCount + 1 Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
End Class
里面用到一个 PrintPreviewControl 一个printdocument 一个printdialog
问题来了:
1、如果执行 PrintDocument1.Print()只能打印出“款号、成本、数量、类型”8个字而下面的数据都是空白
但是在PrintPreviewControl中是可以看到数据的,也就是说数据库那块没错,why?真奇怪。
2、应该有三页但是为什么PrintDocument1.Print()只打印1页?每次开始时有个“正在生成预览”小窗口里面也说有3页
3、怎样让打印预览控件显示第2、3页的内容?
打印? vb.net
[解决办法]
打印范围页
Me.PrintDialog1.PrinterSettings.FromPage
Me.PrintDialog1.PrinterSettings.ToPage
打印指定页
Me.PrintDialog1.PrinterSettings.PrintRange