Home > Software design >  Visual Basic PrintDocument Draw a very long string
Visual Basic PrintDocument Draw a very long string

Time:07-03

e.Graphics.DrawString(srt, font, brush, point) print a string in a straight line.

what if i have a really long, like real long, by that i mean really long string. its just gonna print the string over the paper.

how do i make that the string goes to new line when it hits the margin.

thanks in advanced.

CodePudding user response:

This is a WinForms example with a PictureBox on the form.

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        PictureBox1.Image = New Bitmap(400, 400)
        Using grp = Graphics.FromImage(PictureBox1.Image)
            Dim LongString As String = "THIS IS A  REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY LONG STRING"
            grp.DrawString(LongString, New Font("Arial", 16), New SolidBrush(Color.Black), New Rectangle(100, 100, 200, 200))
            grp.Save()
        End Using
    End Sub
  • Related