Drucken Auszug >>>:
Dim oStringFormat As StringFormat = Nothing
Dim TotalWidth As Integer
'diese Zeile war Fehlerhaft
Static nRowPos As Integer = 0
'hier war der Fehler, musste Static heißen sonst
'Dim nRowPos As Integer = 0 vorher, somit wurde nRowPos
'nicht inizialisiert
Dim NewPage As Boolean = True
Dim _Titel1 As String = " Testseite Bilderspalte drucken"
Dim PageNo As Integer = 1
Dim oColumnLefts As New ArrayList
Dim oColumnWidths As New ArrayList
Dim oColumnTypes As New ArrayList
Dim Height As Integer
Dim Width As Integer
Dim i As Integer
Dim RowsPerPage As Integer
Dim Top As Integer = e.MarginBounds.Top
Dim Left As Integer = e.MarginBounds.Left
If nRowPos >= StromDataGridView.Rows.Count Then nRowPos = 0
TotalWidth = 0
Try
For Each DColumn As DataGridViewColumn In StromDataGridView.Columns
TotalWidth += DColumn.Width
Next
If PageNo = 1 Then
For Each DColumn As DataGridViewColumn In _
StromDataGridView.Columns
Width = CType(Math.Floor(DColumn.Width / TotalWidth * _
TotalWidth * (e.MarginBounds.Width / TotalWidth)), Int16)
Height = e.Graphics.MeasureString(DColumn.HeaderText, _
DColumn.InheritedStyle.Font, Width).Height + 55
oColumnLefts.Add(Left)
oColumnWidths.Add(Width)
oColumnTypes.Add(DColumn.GetType)
Left += Width
Next
End If
Do While nRowPos < StromDataGridView.Rows.Count
Dim oRow As DataGridViewRow = StromDataGridView.Rows(nRowPos)
If Top + Height >= e.MarginBounds.Height + _
e.MarginBounds.Top Then
' ''DrawFooter(e, RowsPerPage)
NewPage = True
PageNo += 1
e.HasMorePages = True
Exit Sub
Else
If NewPage Then
Top = e.MarginBounds.Top
i = 0
For Each oColumn As DataGridViewColumn In _
StromDataGridView.Columns
e.Graphics.FillRectangle(New SolidBrush( _
Drawing.Color.LightGray), New Rectangle( _
oColumnLefts(i), Top, oColumnWidths(i), Height))
e.Graphics.DrawRectangle(Pens.Black, New Rectangle( _
oColumnLefts(i), Top, oColumnWidths(i), Height))
e.Graphics.DrawString(oColumn.HeaderText, _
oColumn.InheritedStyle.Font, New SolidBrush( _
oColumn.InheritedStyle.ForeColor), New RectangleF( _
oColumnLefts(i), Top, oColumnWidths(i), Height), _
oStringFormat)
i += 1
Next
NewPage = False
End If
Top += Height
i = 0
For Each oCell As DataGridViewCell In oRow.Cells
If oColumnTypes(i) Is GetType( _
DataGridViewTextBoxColumn) Then
e.Graphics.DrawString(oCell.Value.ToString, _
oCell.InheritedStyle.Font, New SolidBrush( _
oCell.InheritedStyle.ForeColor), New RectangleF( _
oColumnLefts(i), Top, oColumnWidths(i), Height), _
oStringFormat)
ElseIf oColumnTypes(i) Is GetType( _
DataGridViewImageColumn) Then
Dim oCellSize As Rectangle = New Rectangle( _
oColumnLefts(i), Top, oColumnWidths(i), Height)
Dim oImageSize As Size = CType(oCell.Value, _
Image).Size
e.Graphics.DrawImage(oCell.Value, New Rectangle( _
oColumnLefts(i) + CType(((oCellSize.Width - _
oImageSize.Width) / 2), Int32), Top + CType((( _
oCellSize.Height - oImageSize.Height) / 2), Int32), _
CType(oCell.Value, Image).Width, CType(oCell.Value, _
Image).Height))
End If
e.Graphics.DrawRectangle(Pens.Black, New Rectangle( _
oColumnLefts(i), Top, oColumnWidths(i), Height))
i += 1
Next
End If
nRowPos += 1
RowsPerPage += 1
e.HasMorePages = False
Loop
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try hätte gerne ein Feedback Danke! |