Hi,
da ich etwas gesucht habe um ein Dataset zu Papier zu bringen und ich nicht CR benutzen wollte (aus Lizenzgründen) habe ich mir eine kleine DLL geschrieben für einen Direktdruck oder mit Vorschau.
Also wen es interessiert oder den Code erweitern möchte... hier ist der Code der DLL
(ich nenne diese DLL einfach mal printDSReport.dll)
Zunächst ein neues Projekt (Windowsanwendung) erstellen (Name: printDSReport)
Benennt die Form um in Name: prOvDS
3 Button auf die Form setzen:
1. Button -> Name: PreviewButton
2. Button -> Name: PrintButton
3. Button -> Name: XButton
dann zum Projekt eine neue Klasse (Name:clStart) und ein Modul (Name:modSet)
hinzufügen.
Hier der Code für die Form prOvDS
Private aN As Integer
Private RowPos As Integer
Private rxCols As Integer
Private rxRows As Integer
Private RowsPerPage As Integer
Private pagesToPrint As Integer
Private NextRow As Integer
Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As _
System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
aN = 1
RowPos = 0
NextRow = 0
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e _
As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
pagesToPrint = Math.Ceiling(((myDStoPrint.Tables(0).Rows.Count * _
TxtFont.Height) + (HeaderFont.Height * 4) + (FooterFont.Height * 4) + _
(HeadFont.Height * 4)) / e.MarginBounds.Height)
RowsPerPage = CInt(Math.Floor((e.MarginBounds.Height - ( _
FooterFont.Height * 4) - (HeadFont.Height * 4) - (HeaderFont.Height * _
4)) / TxtFont.Height))
e.Graphics.DrawString(Headertxt, HeaderFont, Brushes.Black, _
e.MarginBounds.Left, e.MarginBounds.Top)
e.Graphics.DrawLine(Pens.Black, e.MarginBounds.Left, e.MarginBounds.Top _
+ 5 + HeaderFont.Height, e.MarginBounds.Width, e.MarginBounds.Top + 5 + _
HeaderFont.Height)
For rxCols = 0 To myDStoPrint.Tables(0).Columns.Count - 1
e.Graphics.DrawString(CStr(myTabSchema(rxCols * 2)), HeadFont, _
Brushes.Black, e.MarginBounds.Left + CInt(myTabSchema(rxCols * 2 _
+ 1)), e.MarginBounds.Top + (HeaderFont.Height * 2))
Next
For rxRows = NextRow To myDStoPrint.Tables(0).Rows.Count - 1
If rxRows > RowsPerPage * aN Then
e.Graphics.DrawString(Now.ToLongDateString + " " + _
Now.ToShortTimeString & " Page " & CStr(aN) & " of " & CStr( _
pagesToPrint), FooterFont, Brushes.Black, _
e.MarginBounds.Left, e.MarginBounds.Height - _
FooterFont.Height)
aN = aN + 1
RowPos = 0
NextRow = rxRows
e.HasMorePages = True
Exit Sub
End If
For rxCols = 0 To myDStoPrint.Tables(0).Columns.Count - 1
e.Graphics.DrawString(CStr(myDStoPrint.Tables(0).Rows( _
rxRows).Item(rxCols)), TxtFont, Brushes.Black, _
e.MarginBounds.Left + CInt(myTabSchema(rxCols * 2 + 1)), _
e.MarginBounds.Top + ((HeadFont.Height * (RowPos + 2)) + ( _
HeaderFont.Height * 2)))
Next rxCols
RowPos = RowPos + 1
Next rxRows
e.Graphics.DrawString(Now.ToLongDateString + " " + _
Now.ToShortTimeString & " Page " & CStr(aN) & " of " & CStr( _
pagesToPrint), FooterFont, Brushes.Black, e.MarginBounds.Left, _
e.MarginBounds.Height - FooterFont.Height)
End Sub
Private Sub PreviewButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles PreviewButton.Click
Dim dlg As New PrintPreviewDialog()
dlg.Document = PrintDocument1
dlg.ShowDialog()
Me.Close()
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles PrintButton.Click
Me.PrintDocument1.Print()
Me.Close()
End Sub
Private Sub XButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles XButton.Click
Me.Close()
End Sub Hier der Code für das Modul modSet
Public myTabSchema As Array
Public myDStoPrint As DataSet
Public Headertxt As String
Public HeaderFont As New Font("Verdana", 14, FontStyle.Bold, _
GraphicsUnit.Pixel)
Public HeadFont As New Font("Verdana", 12, FontStyle.Bold, _
GraphicsUnit.Pixel)
Public TxtFont As New Font("Verdana", 12, FontStyle.Regular, _
GraphicsUnit.Pixel)
Public FooterFont As New Font("Verdana", 10, FontStyle.Regular, _
GraphicsUnit.Pixel) |