另外,如果报表的功能并不是很复杂,就用.NET自带的datareport吧,它与VB6下的报表有质的不同.也很好用的。设计好报表布局后(所见即所得),只需给报表添加数据源即可。
===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
Imports System.Drawing.Printing Public Class Form1 Private printpagesettings As PageSettings Private stringtoprint As String Private printfont As New Font("宋体", 11) Private printfont1 As New Font("宋体", 10, FontStyle.Regular) Private Sub PrintDocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.EndPrint PrintDocument1.Dispose() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Try printpagesettings = New PageSettings PrintDocument1.DefaultPageSettings = printpagesettings stringtoprint = RichTextBox1.Text PrintDialog1.Document = PrintDocument1 PageSetupDialog1.PageSettings = printpagesettings PrintDialog1.PrinterSettings.Copies = 1 ''打印的份数 If PrintDialog1.ShowDialog = DialogResult.OK Then PageSetupDialog1.PageSettings.Landscape = True If PageSetupDialog1.ShowDialog = DialogResult.OK Then AddHandler PrintDocument1.PrintPage, AddressOf Me.printgraphicYDxukezheng PrintDocument1.Print() PrintDocument1.Dispose() RemoveHandler PrintDocument1.PrintPage, AddressOf Me.printgraphicYDxukezheng End If End If 'Catch ex As Exception ' MessageBox.Show("打印出现错误", ex.ToString()) 'End Try End Sub Private Sub printgraphicYDxukezheng(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Dim x As Integer Dim y As Integer x = 990 y = 120 ev.Graphics.DrawString("RichTextBox1.Text", New Font("宋体", 13, FontStyle.Regular), Brushes.Black, 450, 274) ev.Graphics.DrawString("建设单位TextBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 ev.Graphics.DrawString("D新划TextBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 ev.Graphics.DrawString("D位置在TextBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 ev.Graphics.DrawString("D该用地TextBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 ev.Graphics.DrawString("D总面积TextBox.Text" & "用地面积标注ComboBox1.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 ev.Graphics.DrawString("TextBox6.Text & 建设规模标注ComboBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 45 x = x - 35 ev.Graphics.DrawString("建设用地蓝线图:" & "建设用地红线图TextBox.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) ev.Graphics.DrawString("阿图什市规划局", New Font("宋体", 16, FontStyle.Regular), Brushes.Black, 405, 700) ev.Graphics.DrawString("DateTimePicker1.Text", New Font("宋体", 13, FontStyle.Regular), Brushes.Black, 419, 753) Dim numchars As Integer Dim numlines As Integer Dim stringfopage As String Dim strformat As New StringFormat Dim rectdraw As New RectangleF(820, 420, 530, 237) Dim sizemeasure As New SizeF(543, 180 - printfont.GetHeight(ev.Graphics)) strformat.Trimming = StringTrimming.Word ev.Graphics.MeasureString(stringtoprint, printfont, sizemeasure, strformat, numchars, numlines) stringfopage = stringtoprint.Substring(0, numchars) ev.Graphics.DrawString(stringfopage, printfont, Brushes.Black, rectdraw, strformat) x = Nothing y = Nothing ev.HasMorePages = False ev.Graphics.Dispose() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Try printpagesettings = New PageSettings PrintDocument1.DefaultPageSettings = printpagesettings stringtoprint = RichTextBox2.Text PrintDialog1.Document = PrintDocument1 PageSetupDialog1.PageSettings = printpagesettings PrintDialog1.PrinterSettings.Copies = 1 ''打印的份数 If PrintDialog1.ShowDialog = DialogResult.OK Then PageSetupDialog1.PageSettings.Landscape = True If PageSetupDialog1.ShowDialog = DialogResult.OK Then AddHandler PrintDocument1.PrintPage, AddressOf Me.printgraphicxcxukezheng PrintDocument1.Print() PrintDocument1.Dispose() RemoveHandler PrintDocument1.PrintPage, AddressOf Me.printgraphicxcxukezheng End If End If 'Catch ex As Exception ' MessageBox.Show("打印出现错误", ex.ToString()) 'End Try End Sub Private Sub printgraphicxcxukezheng(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Dim x As Integer Dim y As Integer x = 995 y = 110 ev.Graphics.DrawString("RichTextBox2.Text", New Font("宋体", 13, FontStyle.Regular), Brushes.Black, 455, 274) ev.Graphics.DrawString("TextBox39.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 50 ev.Graphics.DrawString("TextBox41.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 50 ev.Graphics.DrawString("ComboBox6.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 50 ev.Graphics.DrawString("TextBox40.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) y = y + 50 ev.Graphics.DrawString("TextBox38.Text", New Font("宋体", 11, FontStyle.Regular), Brushes.Black, x, y) ev.Graphics.DrawString("阿图什市规划局", New Font("宋体", 16, FontStyle.Regular), Brushes.Black, 405, 700) ev.Graphics.DrawString("DateTimePicker4.Text", New Font("宋体", 13, FontStyle.Regular), Brushes.Black, 419, 753) Dim numchars As Integer Dim numlines As Integer Dim stringfopage As String Dim strformat As New StringFormat Dim rectdraw As New RectangleF(820, 325, 530, 237) Dim sizemeasure As New SizeF(543, 180 - printfont.GetHeight(ev.Graphics)) strformat.Trimming = StringTrimming.Word ev.Graphics.MeasureString(stringtoprint, printfont, sizemeasure, strformat, numchars, numlines) stringfopage = stringtoprint.Substring(0, numchars) ev.Graphics.DrawString(stringfopage, printfont, Brushes.Black, rectdraw, strformat) x = Nothing y = Nothing ev.HasMorePages = False End Sub End Class我测试了多次,而且注释掉了所有的TRY,一点儿没有重叠的地方。