I've been working on trying to print stuff in a two-column format recently. I'd really like to print two columns with different non-fixed contents. Based on printing with this code:
...it seems to me that I could declare two rectangles instead of just one (rectDraw above) and print both? And then I would just have to be careful with the iChars < StringToPrint.Length part? If so then it seems to me that this would be pretty easy? Am I barking up the wrong tree or will this work?Code:Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _ ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim iChars As Integer Dim iLines As Integer Dim strForPage As String Dim fmtStringFormat As New StringFormat() Dim iTabStops() As Single = {50, 50, 50, 50} fmtStringFormat.SetTabStops(0, iTabStops) 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)) fmtStringFormat.Trimming = StringTrimming.Word e.Graphics.MeasureString(StringToPrint, PrintFont, sizeMeasure, _ fmtStringFormat, iChars, iLines) strForPage = StringToPrint.Substring(0, iChars) e.Graphics.DrawString(strForPage, PrintFont, Brushes.Black, rectDraw, fmtStringFormat) If iChars < StringToPrint.Length Then StringToPrint = StringToPrint.Substring(iChars) e.HasMorePages = True Else e.HasMorePages = False StringToPrint = rtxtPrintBox.Text End If End Sub




Reply With Quote