Hallo zusammen,
ich möchte das der User aus einem Datagridview die zu druckenden Seiten auswählen kann.
Mein Printdialog sieht so aus:
Spoiler anzeigen
Das Document hat 4 Seiten. Jetzt wird Seite 1-3 gedruckt. Das passt.
Aber wenn ich nochmals auf den Button drcuken drücke wird Seite 4 gedruckt. Ich habe aber bei .BeginPrint Seite =0
Noch eine Frage:
Wie kann ich der Printpage beibringen das zB. nur Seite 2-3 oder 2-4 gedruckt wird ?
Vielen Dank im vorraus....
ich möchte das der User aus einem Datagridview die zu druckenden Seiten auswählen kann.
Mein Printdialog sieht so aus:
VB.NET-Quellcode
- Dim mRow As Integer = 0
- Dim newpage As Boolean = True
- Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
- Seite = 0
- End Sub
- Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
- With DGV_IB
- Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
- fmt.LineAlignment = StringAlignment.Center
- fmt.Trimming = StringTrimming.EllipsisCharacter
- Dim y As Single = e.MarginBounds.Top
- 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 _Hintergrundfarbe As Color = cell.Style.BackColor
- Dim myBrush As New SolidBrush(_Hintergrundfarbe)
- Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
- e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
- 'e.Graphics.FillRectangle(Brushes.LightGray, rc.Left + 1, rc.Top + 1, rc.Width - 1, rc.Height - 1)
- If (newpage) Then
- 'Seitenzahl
- e.Graphics.DrawString(String.Format("Seite {0}", Seite + 1), New Font("arial", 10, FontStyle.Regular), Brushes.Black, New Point(30, 30))
- 'Header grau
- e.Graphics.FillRectangle(Brushes.LightGray, rc.Left + 1, rc.Top + 1, rc.Width - 1, rc.Height - 1)
- e.Graphics.DrawString(DGV_IB.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
- Else
- 'andere Zeilen
- e.Graphics.FillRectangle(myBrush, rc.Left + 1, rc.Top + 1, rc.Width - 1, rc.Height - 1)
- e.Graphics.DrawString(DGV_IB.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
- End If
- x += rc.Width
- h = Math.Max(h, rc.Height)
- Next
- newpage = False
- y += h
- mRow += 1
- If y + h > e.MarginBounds.Bottom Then
- Seite = Seite + 1
- e.HasMorePages = Seite < 3
- mRow -= 1
- newpage = True
- Exit Sub
- End If
- Loop
- mRow = 0
- End With
- End Sub
- Private Sub BT_Perplex_Print_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT_Perplex_Print.Click
- Using ppd = New PrintDialog
- 'DirectCast(ppd.Controls(1), ToolStrip).Visible = False
- PrintDocument1.DefaultPageSettings.Landscape = True
- If ppd.ShowDialog = DialogResult.OK Then
- ppd.Document = PrintDocument1
- ppd.AllowSomePages = True
- PrintDocument1.Print()
- End If
- End Using
- End Sub
Das Document hat 4 Seiten. Jetzt wird Seite 1-3 gedruckt. Das passt.
Aber wenn ich nochmals auf den Button drcuken drücke wird Seite 4 gedruckt. Ich habe aber bei .BeginPrint Seite =0
Noch eine Frage:
Wie kann ich der Printpage beibringen das zB. nur Seite 2-3 oder 2-4 gedruckt wird ?
Vielen Dank im vorraus....