Sie sind auf Seite 1von 2

enter code here Dim mRow As Integer = 0 Dim newpage As Boolean = True

'Print page Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As S ystem.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 'formatting DataGrid With Main.CarinskiDataGridView Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit) fmt.LineAlignment = StringAlignment.Center fmt.Trimming = StringTrimming.EllipsisCharacter 'Format Headers Dim prFont As New Font("Verdana", 22, GraphicsUnit.Point) Dim siFont As New Font("Verdana", 9, GraphicsUnit.Point) Dim hdrFont As New Font("Verdana", 10, FontStyle.Bold) Dim y As Single = e.MarginBounds.Top Dim strInfo As String

'conditional variable If PrintDocument1.DefaultPageSettings.Landscape Then strInfo = "Stranica Ukupno: 5" & vbTab & DateTimePicker1.Value & vbT ab & "" & "" & vbTab & "" & "" e.Graphics.DrawString(vbTab & "" & "", prFont, Brushes.Black, 60, 40 ) e.Graphics.DrawString(strInfo, siFont, Brushes.Black, 110, 80) PrintPreviewDialog.Document = PrintDocument1 PrintDocument1.DefaultPageSettings.Margins.Left = 50 PrintDocument1.DefaultPageSettings.Margins.Right = 50 PrintDocument1.DefaultPageSettings.Margins.Top = 50 PrintDocument1.DefaultPageSettings.Margins.Bottom = 50 y = 120 Else strInfo = "Stranica Ukupno: 5" & vbTab & DateTimePicker1.Value & vbT ab & "" & "" & vbTab & "" & "" e.Graphics.DrawString(vbTab & " Carinski Magacin: " & "Stanje lagera", prFont, Brushes.Black, 5, 40) e.Graphics.DrawString(strInfo, siFont, Brushes.Black, 55, 80) PrintPreviewDialog.Document = PrintDocument1 PrintDocument1.DefaultPageSettings.Margins.Left = 50 PrintDocument1.DefaultPageSettings.Margins.Right = 50 PrintDocument1.DefaultPageSettings.Margins.Top = 50 PrintDocument1.DefaultPageSettings.Margins.Bottom = 50 y = 100 End If 'format hedera datagrida Do While mRow < .RowCount Dim row As DataGridViewRow = .Rows(mRow) Dim x As Single = e.MarginBounds.Left Dim h As Single = 0 For Each cell As DataGridViewCell In row.Cells Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cel

l.Size.Height) 'Format pravougaonika e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height) If (newpage) Then 'Format headera e.Graphics.DrawString(Main.CarinskiDataGridView.Columns(cell .ColumnIndex).HeaderText, .Font, Brushes.Red, rc, fmt) Else 'Format Tabele e.Graphics.DrawString(Main.CarinskiDataGridView.Rows(cell.Ro wIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Blue, rc, fmt) End If 'Brojanje redova x += rc.Width h = Math.Max(h, rc.Height) Next newpage = False y += h mRow += 1 If y + h > e.MarginBounds.Bottom Then e.HasMorePages = True mRow -= 1 newpage = True Exit Sub End If Loop mRow = 0 End With End Sub ''PRINT BUTTON Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.Eve ntArgs) Handles Button1.Click PrintDialog2.Document = PrintDocument1 PrintDialog2.ShowDialog() PrintDocument1.Print() 'PrintDocument1.PrinterSettings.Copies = 2 End Sub

Das könnte Ihnen auch gefallen