Japs, hier meine Lösung
Zuerst der Aufruf der Funktionen.
PS: Das Grid, welches ich benutze kommt nicht aus dem VS, desshalb sehen die Aufrufe etwas anders aus.
Dim newFont As System.Drawing.Font
newFont = New System.Drawing.Font("Tahoma", 7, FontStyle.Bold, _
GraphicsUnit.Pixel)
Dim MaxUmbrueche As Integer = 1
...
MaxUmbrueche = 1
Schrifthoehe1 = 0
'Zeilen werden angefügt, bis das Seitenende ereicht ist.
For iRowCount As Integer = 0 To Grid.Rows.Count - 1
'Tabellenfelder werden übergeben.
For iCellCount As Integer = 0 To Grid.Rows( _
iRowCount).Cells.Count - 1
If MaxUmbrueche < TextUmbrueche(Grid.Rows(iRowCount).Cells( _
iCellCount).Text, newFont, Grid.Rows(0).Cells( _
iCellCount).Width) Then
MaxUmbrueche = TextUmbrueche(Grid.Rows( _
iRowCount).Cells(iCellCount).Text, newFont, Grid.Rows( _
0).Cells(iCellCount).Width)
End If
Next
Schrifthoehe1 = Schrifthoehe(newFont)
For iCellCount As Integer = 0 To Grid.Rows( _
iRowCount).Cells.Count - 1
If Grid.Rows(iRowCount).Cells(iCellCount).Column.Hidden = _
False Then
'Rechteck wird gezeichnet
rect1.X = xAbstand
rect1.Y = yAbstand
rect1.Width = Grid.Rows(0).Cells(iCellCount).Width
If (Schrifthoehe1 * MaxUmbrueche) > Grid.Rows( _
0).Height Then
rect1.Height = (Schrifthoehe1 * MaxUmbrueche)
Else
rect1.Height = (Grid.Rows(0).Height)
End If
g.DrawRectangle(Pens.Black, xAbstand, yAbstand, _
rect1.Width, rect1.Height) 'Grid.Rows(0).Cells(
' iCellCount).Column.Header.Height)
'Text des Feldes wird gezeichent.
g.DrawString(Grid.Rows(iRowCount).Cells( _
iCellCount).Text, newFont, Brushes.Black, rect1)
xAbstand = xAbstand + Grid.Rows(0).Cells( _
iCellCount).Width
lastHeight = rect1.Height
End If
Next
.... Und hier die Funktionen Private frmTestGrafik As New System.Windows.Forms.Form
Public Function TextUmbrueche(ByVal Text As String, ByVal Schrift As Font, _
ByVal Feldbreite As Integer) As Integer
Dim s As String = ""
Dim Umbrueche As Integer = 1
Dim StartVal As Integer = 1
Dim g As System.Drawing.Graphics = frmTestGrafik.CreateGraphics
Dim sf As SizeF
For i As Integer = 1 To Text.Length
s = Mid(Text, StartVal, i - StartVal + 1)
sf = g.MeasureString(s, Schrift)
If sf.Width > Feldbreite Then
Umbrueche = Umbrueche + 1
StartVal = i
End If
Next
g.Dispose()
Return Umbrueche
End Function
Public Function Schrifthoehe(ByVal Schrift As Font) As Double
Dim frm As New System.Windows.Forms.Form
Dim g As System.Drawing.Graphics = frm.CreateGraphics
Dim sf As SizeF
sf = g.MeasureString("Tg", Schrift)
g.Dispose()
Return sf.Height
End Function Ich hoffe es hilft Dir.
Gru? Rub
(PS: Besuch doch mal meine Seiten http://e-liquids.de und http://jjpassion.de) |