I am new to Visual Basic and am currently taking a class that is teaching me the basics. I have almost completed my final project, but have come to a roadblock when trying to print strings from my different labels on the form. I have Directions and Descriptions that appear in these labels and are various character lengths. I want to put these labels on a printed document but have no clue how to get them to word wrap. My book has nothing on the matter and I am at a loss. As of now I have the print preview working for the most part, but the strings run of the page. Here are my print subprocedures so far.
I am new to this and don't know where to begin with word wrapping, all of the examples I have searched I don't understand and any feeback would be greatly appreciated. Thanks
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click 'Call the subprogram PrintDocument1_PrintPage to create a page to be displayed PrintPreviewDialog1.Document = PrintDocument1 'Display the created page in a PrintPreviewDialog box PrintPreviewDialog1.ShowDialog() End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 'LeftMarginSingle and TopMarginSingle set at top and left of page Dim LeftMarginInteger As Integer = e.MarginBounds.Left Dim TopMarginIntger As Integer = e.MarginBounds.Top Dim RightMarginInteger As Integer = e.PageBounds.Right 'specify font Dim PrintFont As New Font("Arial", 12, FontStyle.Bold) 'LineHeightSingle is the number of pixels to skip down for next line Dim LineHeightinteger As Integer = CInt(PrintFont.GetHeight + 2) 'PrintLineString will hold string components to print Dim PrintLineString As String ' The horizontal and vertical print positions Dim XPosition, YPosition, Sposition As Integer 'start the print position at the left and top margins XPosition = LeftMarginInteger YPosition = TopMarginIntger Sposition = RightMarginInteger 'skip down 2 lines YPosition += 2 * LineHeightinteger 'select map from picturebox 2 Dim newimage As Image = PictureBox2.Image 'Draw image on document e.Graphics.DrawImage(newimage, 100, 80) 'Skip down 26 lines YPosition += 26 * LineHeightinteger 'Put the Trip Label into the string variable PrintLineString PrintLineString = TripLabel.Text 'Print the string variable e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, XPosition + 280, YPosition) 'Skip down 2 lines YPosition += 2 * LineHeightinteger 'Put Directions Label into string variable PrintLineString PrintLineString = DirectionsLabel.Text 'Print String Variable e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, XPosition, YPosition) 'Skip down 8 lines YPosition += 8 * LineHeightinteger 'Put Description Lable into string variable PrintLineString PrintLineString = DescriptionLabel.Text 'Print string Variable e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, XPosition, YPosition) End Sub
I am new to this and don't know where to begin with word wrapping, all of the examples I have searched I don't understand and any feeback would be greatly appreciated. Thanks