'Dans une Form insère un bouton (button1), un textbox (Textbox1) multiline ou pas, et un PrintDocument (PrintDocument1); 'En suite pour imprimer le contenu du textbox sur ton imprimante par défaut, clique sur le bouton: Option Explicit On Option Strict On Public Class Form1 Dim Str As String Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Str = TextBox1.Text PrintDocument1.Print() End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim numChars As Integer Dim numLines As Integer Dim stringForPage As String Dim strFormat As New StringFormat() Dim PrintFont As Font PrintFont = TextBox1.Font Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height) Dim sizeMeasure As New SizeF(e.MarginBounds.Width, e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics)) strFormat.Trimming = StringTrimming.Word e.Graphics.MeasureString(Str, PrintFont, sizeMeasure, strFormat, numChars, numLines) stringForPage = Str.Substring(0, numChars) e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat) If numChars < Str.Length Then Str = Str.Substring(numChars) e.HasMorePages = True Else e.HasMorePages = False End If End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionc'est bon j'ai trouvé la solution