Bryanjar sei un genio. Grazie di cuore alla fine sempre gli stessi restano i migliori e aiutano davvero le persone .
grazie
Però c'è solo una cosa. no mi segnala errori solo che va in blocco.
non so perchè.
cioè si incanta la form
questo è il codice completo compreso il tuo gia sostituito
codice:
Imports System.IO
Imports System.Drawing.Printing
Imports Microsoft.VisualBasic
Public Class Form3
Inherits System.Windows.Forms.Form
Private printFont As Font
Private streamToPrint As StreamReader
Private Shared filePath As String
' Print the file.
Private Sub Printing()
Try
streamToPrint = New StreamReader("C:\App.txt")
Try
printFont = New Font("Arial", 10)
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Print the document.
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'The PrintPage event is raised for each page _ to be printed.
Private Sub pd_PrintPage(ByVal sender As Object, _
ByVal ev As 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 line As String = Nothing
' Calculate the number of lines per page.
linesPerPage = _
ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
' Iterate over the file, printing each line.
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = _
topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, _
leftMargin, 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
' The PrintPage event is raised for each page _to be printed.
Public Function ParseTextBox(ByVal RowLen As Integer, ByVal RowText As String) As String
Dim sRet, sToken As String
Dim nC As Integer
Dim sCR As String = Microsoft.VisualBasic.Constants.vbCrLf
Dim mRowText As String
' Rimpiazza tutti i CRLF con degli spazi
' --------------------------------------
mRowText = Microsoft.VisualBasic.Replace(RowText, sCR, " ")
sRet = ""
nC = 0
Do While Len(mRowText) > 0
' Se la lunghezza dela strimga rimanente è minore
' della larghezza massima, aggiungo la rimanenza ed esco
If Microsoft.VisualBasic.Len(mRowText) < RowLen Then
sRet = sRet + sCR + mRowText
Exit Do
End If
If RowLen > nC Then
sToken = Microsoft.VisualBasic.Mid(mRowText, 1, (RowLen - nC))
Else
Exit Do
End If
If Microsoft.VisualBasic.Right(sToken, 1) <> " " Then
nC = nC + 1
Else
sRet = sRet + sCR + sToken
mRowText = Microsoft.VisualBasic.Mid(mRowText, (RowLen - nC))
nC = 0
End If
Loop
Return sRet
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim fFile As StreamWriter
Dim strDoc As String = ""
strDoc = strDoc + TextBox21.Text + vbCrLf + vbCrLf
strDoc = strDoc + TextBox24.Text + vbCrLf + vbCrLf
strDoc = strDoc + TextBox22.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox21.Text) + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(40, TextBox1.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox11.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox2.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox12.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox3.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox13.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox4.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox14.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox5.Text) + vbCrLf + vbCrLf
strDoc = strDoc + TextBox15.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox6.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox16.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox7.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox17.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox8.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox18.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox9.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox19.Text + vbCrLf + vbCrLf
strDoc = strDoc + ParseTextBox(120, TextBox10.Text) + vbCrLf + vbCrLf
strDoc = strDoc + " " + TextBox20.Text + vbCrLf + vbCrLf
fFile = File.CreateText("C:\App.txt")
fFile.WriteLine(strDoc)
fFile.Close()
Printing()
File.Delete("C:\App.txt")
End Sub
End Class
sei puoi dacci un occhiata quando non hai nulla da fare. di sicuro ci sarà qualche errore banale.
mahhhh
grazieeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeee