Salve.
Per stampare su un modulo continuo utilizzo il seguente codice, ovviamente trovato sulla guida MSDN:
Il documento viene stampato correttamente, ma il margine destro è troppo stretto, per cui non stampa l'ultimo carattere a destra.codice:Public Sub Stampa() Dim OldStampante As String Dim Pd As Printing.PrintDocument Try streamToPrint = New System.IO.StreamReader(Application.StartupPath & "\stampa.txt") Try printFont = New Font("Courier", 10) Pd = New Printing.PrintDocument AddHandler Pd.PrintPage, AddressOf pd_PrintPage OldStampante = Pd.PrinterSettings.PrinterName 'stampante da configurazione Pd.PrinterSettings.PrinterName = sStampante Pd.Print() Finally streamToPrint.Close() streamToPrint = Nothing IO.File.Delete(Application.StartupPath & "\stampa.txt") Pd.PrinterSettings.PrinterName = OldStampante End Try Catch ex As Exception Pd.PrinterSettings.PrinterName = OldStampante MessageBox.Show(ex.Message) End Try End Sub Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs) Dim linesPerPage As Single = 0 Dim yPos As Single = 0 Dim count As Integer = 0 Dim leftMargin As Single = ev.MarginBounds.Left Dim topMargin As Single = ev.MarginBounds.Top Dim rightMargin As Single = ev.MarginBounds.Right Dim line As String = Nothing ' Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ' Print each line of the file. While count < linesPerPage line = streamToPrint.ReadLine() If line Is Nothing Then Exit While End If yPos = 50 + count * printFont.GetHeight(ev.Graphics) ev.Graphics.DrawString(line, printFont, Brushes.Black, 31, yPos, New StringFormat) count += 1 End While ' If more lines exist, print another page. If Not (line Is Nothing) Then ev.HasMorePages = True Else ev.HasMorePages = False End If End Sub
Non riesco a settare questo margine per aumentarlo.
La stampante l'ho dovuta mettere come "Generic text only" perchè con i driver normali non mi accetta il font COURIER, che mi serve...
Grazie

Rispondi quotando