Omlouvám se za neúplné informace. Program je napsán pod VB 2008. Přikládám code. Děkuji za pomoc.
PageSetupDialog1.PageSettings = PrintDocument1.DefaultPageSettings
If PageSetupDialog1.ShowDialog = DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
Try
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()
Catch ex As Exception
I = MsgBox("Tisk nebyl dokončen" & vbCrLf & _
ex.Message, MsgBoxStyle.OkOnly, "Pokus tisknout")
End Try
Else
I = MsgBox("Tisk byl zrušen")
End If
***********************************
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static CurrentChar As Int32
Dim txtFont As New Font("Courier New", 10)
Dim txtH As Int16
Dim txtW As Int16
Dim LMargin, TMargin As Int16
With PrintDocument1.DefaultPageSettings
txtH = .PaperSize.Height - .Margins.Top - .Margins.Bottom
txtW = .PaperSize.Width - .Margins.Left - .Margins.Right
LMargin = PrintDocument1.DefaultPageSettings.Margins.Left
TMargin = PrintDocument1.DefaultPageSettings.Margins.Top
End With
If PrintDocument1.DefaultPageSettings.Landscape Then
Dim tmp As Int16
tmp = txtH
txtH = txtW
txtW = tmp
End If
Dim LineSperPage As Int32 = txtH / txtFont.Height
Dim R As New RectangleF(LMargin, TMargin, txtW, txtH)
Dim Lines, Chars As Int32
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
e.Graphics.MeasureString(Mid(TextToPrint, CurrentChar + 1), txtFont, New SizeF(txtW, txtH), fmt, Chars, Lines)
e.Graphics.DrawString(Mid(TextToPrint, CurrentChar + 1), txtFont, Brushes.Black, R, fmt)
CurrentChar = CurrentChar + Chars
If CurrentChar < TextToPrint.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
CurrentChar = 0
End If
End Sub
|