onInit überladen ?
Der code:
Imports System.Drawing.Graphics
Imports System.Drawing.Printing
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents PrintDocument1 As New PrintDocument
Public strDruckString As String
Dim strFont As String = "ARIAL"
Dim intfontsize As Integer = 12
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim ps As New System.Drawing.Printing.PrinterSettings
For i As Integer = 0 To _
System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count - 1
Me.ComboBox1.Items.Add( _
System.Drawing.Printing.PrinterSettings.InstalledPrinters(i))
If ps.PrinterName.ToUpper.Equals( _
System.Drawing.Printing.PrinterSettings.InstalledPrinters( _
i).ToUpper) Then
Me.ComboBox1.SelectedIndex = i
End If
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button3.Click
Try
strDruckString = ""
strDruckString &= "Tisch Nr. 1" & vbCrLf
strDruckString &= "Bedienung: Timo" & vbCrLf
strDruckString &= "Uhrzeit: 11:56 Uhr" & vbCrLf
strDruckString &= "------------" & vbCrLf
strDruckString &= "Hauptgericht" & vbCrLf
strDruckString &= "------------" & vbCrLf
strDruckString &= "1 Jaegerschnitzel-Pommes-Salat" & vbCrLf
strDruckString &= "2 Zigeunerschnitzel-Kroketten-Salat" & vbCrLf
strDruckString &= "------------" & vbCrLf
strDruckString &= "------------" & vbCrLf
strDruckString &= "------------" & vbCrLf
strDruckString &= "Tisch Nr. 1" & vbCrLf
strDruckString &= "Bedienung: Timo" & vbCrLf
strDruckString &= "Uhrzeit: 11:56 Uhr" & vbCrLf
PrintDocument1.PrinterSettings.PrinterName = ComboBox1.Text
PrintDocument1.Print()
Catch ex As Exception
MessageBox.Show(ex.ToString & vbCrLf & ex.StackTrace)
End Try
End Sub
Sub printDocument1_print(ByVal sender As Object, ByVal e As _
PrintPageEventArgs) Handles PrintDocument1.PrintPage
Try
Static intCurrentChar As Int32
Dim font As New Font(strFont, intfontsize)
Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As _
Int32
With PrintDocument1.DefaultPageSettings
intPrintAreaHeight = .PaperSize.Height - .Margins.Top - _
.Margins.Bottom
intPrintAreaWidth = .PaperSize.Width + 90
marginLeft = 4
marginTop = .Margins.Top
End With
If PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = intPrintAreaHeight
intPrintAreaHeight = intPrintAreaWidth
intPrintAreaWidth = intTemp
End If
Dim intLineCount As Int32 = CInt(intPrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, _
intPrintAreaWidth, intPrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(strDruckString, intCurrentChar + 1), _
font, New SizeF(intPrintAreaWidth, intPrintAreaHeight), fmt, _
intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(strDruckString, intCurrentChar + 1), _
font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
If intCurrentChar < strDruckString.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
intCurrentChar = 0
End If
Catch ex As Exception
MessageBox.Show(ex.ToString & vbCrLf & ex.StackTrace)
End Try
End Sub Gruß
Lars |