Danke für das Beispiel, bezieht sich aber nur auf eine TextBox
ich habe aber eine DGV bzw. Datasource da muss ich wohl alles Zufuss machen
Beispiel Zeilen_Spalten der (DGV) ermitteln
nur so wie unten im Code, geht das nicht da meine 2 DGV unter Kopfzeile soll
Private Sub PD_Streifenliste_Zeilen_Spalten_Ermitteln()
Dim ImageWall As Bitmap
ImageWall = New Bitmap(CInt(rect_Druckbereich.Width), CInt( _
rect_Druckbereich.Height))
Using g As Graphics = Graphics.FromImage(ImageWall)
g.PageUnit = GraphicsUnit.Display
DruckSeite = 1
Dim DGV_Font As Font = New System.Drawing.Font("Tahoma", 8.25!, _
System.Drawing.FontStyle.Regular, _
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Dim ZellInhalt As String
Dim Höhe As Integer = 0
Dim maxHöhe As Integer = 0
Dim Breite As Single = rect_Druckbereich.Width
ZeilenHoehen.Clear()
SpaltenBreiten.Clear()
'relativ feste Breiten
Dim w1 As Single = g.MeasureString("-0000-", DGV_Font).Width _
'MeldeID
Dim w2 As Single = g.MeasureString("-Erstellt am-", DGV_Font).Width _
'Erstelldatum
Dim w3 As Single = g.MeasureString( _
"-Problem-Problembeschreibung-Meldung-Problem-Problembeschreibung-"_
, DGV_Font).Width 'Meldetext
Dim w4 As Single = g.MeasureString("-TPM-Karte-", DGV_Font).Width _
'TPM-Karte
Dim w5 As Single = g.MeasureString( _
"-SLS-GC-H6-Linie-FB-CM-9393906-", DGV_Font).Width 'Maschine,Anlage
Dim w6 As Single = g.MeasureString("-Ort-", DGV_Font).Width 'Ort,
' Halle
Dim w7 As Single = g.MeasureString("-Anrede-Name,Vorname-", _
DGV_Font).Width 'Name Melder
Dim w8 As Single = g.MeasureString("-dd.MM.YYYY-", DGV_Font).Width _
'Datum abgestellt
Dim w9 As Single = g.MeasureString("-erledigt-", DGV_Font).Width _
'OK, Problem abgestellt
Dim wG As Single = w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9
Dim PrzSatz As Single = (wG / Breite) * 100
'restliche 3 Spaltenbreiten dritteln
Dim drittelPrzSatz As Single = (100 - PrzSatz) / 3
Dim drittelBreite As Single = (drittelPrzSatz * Breite) / 100
SpaltenBreiten.Add(w1) 'MeldeID
SpaltenBreiten.Add(w2) 'Erstelldatum
SpaltenBreiten.Add(w3) 'Meldetext
SpaltenBreiten.Add(w4) 'TPM-Karte
SpaltenBreiten.Add(w5) 'Maschine,Anlage
SpaltenBreiten.Add(w6) 'Ort
SpaltenBreiten.Add(w7) 'Melder
SpaltenBreiten.Add(w8) 'Datum abgestellt
SpaltenBreiten.Add(w9) 'OK abgearbeitet, abgestellt
'
Dim curr_Zelle As DataGridViewCell = Nothing
Dim ZellBox As New RectangleF
Dim sfmt As New StringFormat
sfmt = StringFormat.GenericDefault
sfmt.Alignment = StringAlignment.Center
sfmt.LineAlignment = StringAlignment.Center
Dim ZeilenHöhe As Single = g.MeasureString("[Wü gq*µ']", _
DGV_Font).Height
Dim charactersFitted, linesFilled As Integer
Dim tmp_size As New SizeF
Dim gsize As New SizeF
Dim aktHöhe As Integer
For DGVZeile As Integer = 0 To DGV.Rows.Count - 1
maxHöhe = 0
Höhe = 0
For DGVSpalte As Integer = 0 To DGV.Columns.Count - 1
curr_Zelle = DGV.Rows(DGVZeile).Cells(DGVSpalte)
ZellInhalt = curr_Zelle.FormattedValue.ToString
'Höhenmessung
tmp_size.Width = SpaltenBreiten(DGVSpalte)
tmp_size.Height = rect_Druckbereich.Height
'Anzahl benötigter Zeilen ermitteln (linesFilled)
gsize = g.MeasureString(ZellInhalt, DGV_Font, tmp_size, _
sfmt, charactersFitted, linesFilled)
aktHöhe = CInt(Math.Ceiling((ZeilenHöhe * linesFilled)))
Höhe = Math.Max(Höhe, aktHöhe)
maxHöhe = Math.Max(Höhe, maxHöhe)
Next
ZeilenHoehen.Add(maxHöhe + 2)
Next
DGV_Font.Dispose()
sfmt.Dispose()
curr_Zelle.Dispose()
End Using
ImageWall.Dispose()
End Sub |