Vielleicht so was ....
Public Class frmListViewDemo2
'Panel mit Scrollbalken
Dim pl As New Panel With _
{.Parent = Me, .Width = 400, .Height = 400, _
.AutoScroll = True}
'Picturebox für die Anzeige
Dim pbox As New PictureBox With _
{.Parent = pl, _
.SizeMode = PictureBoxSizeMode.AutoSize}
Dim col() As String 'Spaltenüberschriften
Dim bmp As Bitmap 'Bitmap für Datenaufbereitung
Private Sub frmListViewDemo2_Load(sender As System.Object, _
e As System.EventArgs) Handles MyBase.Load
Me.ClientSize = pl.Size
col =
{"Bearbeitungsindex", "Durchmesser", "XSoll", "YSoll", _
"TiefeSoll", "Aggregat", "Werkzeugnummer"}
'Zeilen lesen
Dim lines() As String = _
IO.File.ReadAllLines("C:\daten\001030777965L.txt")
Dim fields As New List(Of String)
'Zahl der Ausgabezeilen ermitteln
Dim linecounter As Integer
For l As Integer = 0 To lines.Count - 1
If lines(l).Trim.StartsWith(col(0)) Then linecounter += 1
Next l
Dim fo As New Font("Arial", 10) 'Font der Ausgabe
Dim fieldwidth As Integer = 80 'Feldgröße (an Font anzupassen)
Dim fieldheight As Integer = 15
Dim margin As Integer = 20 'Randbreite
'Ausgabe-Bitmap erstellen
Dim bmp_width As Integer = _
fieldwidth * col.Length + 2 * margin
Dim bmp_height As Integer = _
fieldheight * (linecounter + 1) + 2 * margin
bmp = New Bitmap(bmp_width, bmp_height)
linecounter = 0
Dim text As String
'Texte in die Bitmap eintragen
Using g As Graphics = Graphics.FromImage(bmp), _
b As New SolidBrush(Color.Black)
'Hintergrundfarbe
g.Clear(Color.White)
'Überschriften ausgeben
For i As Integer = 0 To col.Length - 1
text = AdjustLength(g, fo, col(i), fieldwidth)
g.DrawString(text, fo, b, _
New Point(margin + i * fieldwidth, margin))
Next i
For l As Integer = 0 To lines.Count - 1
Dim parts() As String = lines(l).Split("="c)
If lines(l).Trim.StartsWith(col(0)) Then
For k As Integer = 0 To col.Length - 1
fields.Add("")
Next k
End If
Dim id As Integer = Array.IndexOf(col, parts(0))
If id >= 0 AndAlso fields.Count > id Then
fields(id) = parts(1)
'Ausgabe-Zeile vollständig aufbereitet ?
Dim ok As Boolean = True
For i As Integer = 0 To fields.Count - 1
If fields(i) = "" Then ok = False
Next i
If ok Then
'Felder in einer Zeile ausgeben
linecounter += 1
For i As Integer = 0 To fields.Count - 1
text = AdjustLength(g, fo, fields(i), fieldwidth)
g.DrawString(text, fo, b, _
New Point(margin + i * fieldwidth, _
margin + linecounter * fieldheight))
Next i
fields.Clear()
End If
End If
Next l
End Using
pbox.Image = bmp 'Bitmap anzeigen
End Sub
Private Function AdjustLength(g As Graphics, fo As Font, _
text As String, length As Integer) As String
Dim l As Integer = text.Length + 1
Do
l -= 1
text = text.Substring(0, l)
Loop While g.MeasureString(text, fo).Width > length
While g.MeasureString(text, fo).Width < length
text = " " & text
End While
Return text
End Function
End Class |