Hallo ich bin ein wenig genervt,
ich begreife die druckerei noch nicht.
Wo bzw. wie kann ich meine Spalten mit StringFormat,
LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center, oder links bzw rechts ausrichten
zum Beispiel in der Spalte 4 stehen Double Werte die möchte ich natürlich rechts ausrichten
oder die erste Spalte 0 möchte ich auch ausrichten nach rechts alle ausser die Imagespalte
hier der code aus der Klasse zum drucken der DGV:
With e.Graphics
Static x As Integer = 40
Static y As Integer = 40
Static h As Integer = 90
Static BP As New Pen(Brushes.Black, 1)
Static pagenumber As Integer = 1
Static rowsperpage As Integer = 19
Dim g = e.Graphics
Dim pagesCount As Integer = 1
If DGV.RowCount > 17 Then
pagesCount += CInt(Math.Ceiling((DGV.RowCount - 15) / 19))
End If
Dim w As Integer = 0
Static currentRow As Integer = 0
Static footFont As New Font("Microsoft Sans Serif", 12, _
FontStyle.Regular)
Static pFont As New Font("Microsoft Sans Serif", 9, _
FontStyle.Regular)
Static pFontU As New Font("Microsoft Sans Serif", 20, _
FontStyle.Regular)
Static Fonttitel2 As New Font("Microsoft Sans Serif", 12, _
FontStyle.Regular)
Dim ColumnWidthsPercent(DGV.ColumnCount - 1) As Double
Dim FullSize As Integer = 0
For i As Integer = 0 To ColumnWidthsPercent.Length - 1
ColumnWidthsPercent(i) = DGV.Columns(i).Width
FullSize += DGV.Columns(i).Width
Next
If currentRow = 0 Then
Dim strTitel1 As String = "| Meine Liste |"
Dim strTitel2 As String = String.Empty
.DrawImage(newImage, x, y, newImage.Width, newImage.Height)
.DrawString(strTitel1, pFontU, Brushes.Black, x + _
newImage.Width + 10, y + 7)
.DrawString(strTitel2, Fonttitel2, Brushes.Black, x + _
newImage.Width + 10, y + 40)
y += newImage.Height + 15
End If
For i As Integer = 0 To ColumnWidthsPercent.Length - 1
ColumnWidthsPercent(i) = MaxWidth / 100 * ColumnWidthsPercent( _
i) / FullSize * 100
w = CInt(ColumnWidthsPercent(i))
.FillRectangle(New SolidBrush(Color.LightSkyBlue), x, y, w, h)
.DrawString(DGV.Columns(i).HeaderText, pFont, Brushes.Black, _
New Rectangle(x, y, w, h), SF)
.DrawRectangle(BP, x, y, w, h)
x += w
Next
x = 40
y += h
While currentRow < DGV.RowCount
For i As Integer = 0 To ColumnWidthsPercent.Length - 1
w = CInt(ColumnWidthsPercent(i))
.DrawRectangle(BP, x, y, w, h)
'hier wird zuerst gepüft ob in der Zeile eine Imagecolumn gibt
' dann soll da ein Bild gedruckt werden.
If TypeOf (Me.DGV.Columns(i)) Is DataGridViewImageColumn Then
Dim img As Image = CType(DGV.Rows(currentRow).Cells( _
i).Value, Image)
g.DrawImageUnscaled(img, New Rectangle(x + 6, y + 6, w, _
h))
Else
'hier werden dann die anderen Columns als String
' gedruckt
'(mir fehlt noch das ausrichten der spalten links,
' rechts oder mittig)
.DrawString(DGV.Rows(currentRow).Cells( _
i).FormattedValue.ToString, pFont, Brushes.Black, New _
Rectangle(x, y, w, h), SF)
End If
x += w
Next
x = 40
y += h
currentRow += 1
If y + h > MaxHeight AndAlso Not currentRow = DGV.RowCount Then
e.HasMorePages = True
Exit While
End If
End While
'#
Dim myDatum As String = "Druck Datum: " & Format(Now, "dd.MM.yyyy")
Dim strErsteller As String = "Ersteller .........."
.DrawString(myDatum, footFont, Brushes.Black, x, 1090)
.DrawString(strErsteller, footFont, Brushes.Black, x, 1110)
.DrawString("Seite " & pagenumber & " / " & pagesCount, footFont, _
Brushes.Black, x + 400, 1110)
x = 40
y = 40
pagenumber += 1
If Not e.HasMorePages Then
pagenumber = 1
currentRow = 0
End If
End With für eure Hilfe Danke.
PS die ImageColumnspalte muss aber nach wie vor funktionieren |