vb.netprintdocument

Visual Basic PrintDocument Draw a very long string


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.


Solution

  • 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 oFont As Font = New Font("Arial", 16)
                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, oFont, Brushes.Black, New Rectangle(100, 100, 200, 200))
                    grp.Save()
                End Using
            End Using
        End Sub