So, ich habe Deinen Code (angepaßt an unsere Etiketten-Größe) direkt mal am Etiketten-Drucker ausprobiert...hier das Ergebnis.
Jetzt müßte der Rand oben links nur noch eine Zeile höher und eine Reihe weiter links,
damit alle 6 Etiketten gedruckt werden.
Und diese 3 freien Zeilen, wenn ich nur wüßte, wie ich die verhindern könnte.
Imports System.Drawing.Printing
Public Class frmPrintDemoV2
Dim WithEvents button1 As New Button With {.Parent = Me, .Text = "Drucken"}
Dim zähler As Integer = 0
Dim arr As New List(Of String)
Dim schriftart As New Font("Arial", 12, FontStyle.Regular)
Private WithEvents doc As New PrintDocument()
'Angabe zu der Größe und Position des Druckbereichs der Etiketten
'in Millimeter
Dim edb_breite As Single = 30
Dim edb_höhe As Single = 23
Dim edb_abstandX As Single = 5
Dim edb_abstandY As Single = 2.4
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
For a As Integer = 0 To 73
arr.Add("Nummer " & CStr(a) & vbCrLf & _
"Kennung" & vbCrLf & Now.ToString)
Next a
End Sub
Private Sub Draw(ByVal g As Graphics, ByVal e As PrintPageEventArgs)
Dim br As New SolidBrush(Color.Black)
Dim f As Font = schriftart
Dim x, y As Single
x = CSng(e.PageSettings.Margins.Left * 25.4 / 100) '1/100 Zoll in
' Millimeter
y = CSng(e.PageSettings.Margins.Top * 25.4 / 100)
For i As Integer = zähler To arr.Count - 1
If (i + 1) Mod 6 = 0 Then
Dim h As Integer = CInt(Math.Ceiling(g.MeasureString(arr(i), _
f).Height))
g.DrawString(arr(i), f, br, _
New RectangleF(New PointF(x, y), New SizeF(edb_breite, _
edb_höhe)), _
StringFormat.GenericDefault)
x = CSng(e.PageSettings.Margins.Left * 25.4 / 100)
y += (edb_abstandY + edb_höhe)
Else
g.DrawString(arr(i), f, br, _
New RectangleF(New PointF(x, y), New SizeF(edb_breite, _
edb_höhe)), _
StringFormat.GenericDefault)
x += (edb_abstandX + edb_breite)
End If
zähler += 1
If (y - edb_abstandY) > e.MarginBounds.Height * 25.4 / 100 Then _
Exit For
Next i
End Sub
Private Sub Drucker(ByVal sender As Object, ByVal e As PrintPageEventArgs) _
Handles doc.PrintPage
Dim g As Graphics = e.Graphics
g.PageUnit = GraphicsUnit.Millimeter
g.TextRenderingHint = _
Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
Me.Draw(g, e)
e.HasMorePages = zähler < arr.Count - 1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles button1.Click
zähler = 0
doc.Print()
End Sub
End Class
Beitrag wurde zuletzt am 15.11.13 um 14:32:05 editiert. |