|
-
Oct 8th, 2002, 04:03 AM
#1
Thread Starter
Fanatic Member
*resolved* "Right way" to print two-column documents?
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:
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
...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?
Last edited by Slow_Learner; Oct 8th, 2002 at 05:00 AM.
-
Oct 8th, 2002, 04:46 AM
#2
Thread Starter
Fanatic Member
This *almost* works:
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim iCharsLeftColumn, iCharsRightColumn As Integer
Dim iLinesLeftColumn, iLinesRightColumn As Integer
Dim strForPageLeftColumn, strForPageRightColumn As String
Dim fmtStringFormat As New StringFormat()
Dim iTabStops() As Single = {50, 50, 50, 50}
fmtStringFormat.SetTabStops(0, iTabStops)
Dim rectLeftColumn As New RectangleF( _
e.MarginBounds.Left, e.MarginBounds.Top, _
(e.MarginBounds.Width / 2) - 10, e.MarginBounds.Height)
Dim rectRightColumn As New RectangleF( _
(e.MarginBounds.Width / 2) + 10, e.MarginBounds.Top, _
e.MarginBounds.Width, e.MarginBounds.Height)
Dim sizeMeasure As New SizeF((e.MarginBounds.Width / 2) - 10, _
e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))
fmtStringFormat.Trimming = StringTrimming.Word
e.Graphics.MeasureString(strPrintLeftColumn, PrintFont, sizeMeasure, _
fmtStringFormat, iCharsLeftColumn, iLinesLeftColumn)
e.Graphics.MeasureString(strPrintRightColumn, PrintFont, sizeMeasure, _
fmtStringFormat, iCharsRightColumn, iLinesRightColumn)
strForPageLeftColumn = strPrintLeftColumn.Substring(0, iCharsLeftColumn)
strForPageRightColumn = strPrintRightColumn.Substring(0, iCharsRightColumn)
e.Graphics.DrawString(strForPageLeftColumn, PrintFont, Brushes.Black, rectLeftColumn, _
fmtStringFormat)
e.Graphics.DrawString(strForPageRightColumn, PrintFont, Brushes.Black, rectRightColumn, _
fmtStringFormat)
If iCharsLeftColumn < strPrintLeftColumn.Length Then
strPrintLeftColumn = strPrintLeftColumn.Substring(iCharsLeftColumn)
Else
strPrintLeftColumn = rtxtPrintLeftColumn.Text
End If
If iCharsRightColumn < strPrintRightColumn.Length Then
strPrintRightColumn = strPrintRightColumn.Substring(iCharsRightColumn)
Else
strPrintRightColumn = rtxtPrintRightColumn.Text
End If
If iCharsLeftColumn < strPrintLeftColumn.Length Or _
iCharsRightColumn < strPrintRightColumn.Length Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
...except my rectangles are overlapping. *stares stupidly at RectangleF constructor docs*
-
Oct 8th, 2002, 04:59 AM
#3
Thread Starter
Fanatic Member
duh
Code:
Dim rectLeftColumn As New RectangleF( _
e.MarginBounds.Left, e.MarginBounds.Top, _
(e.MarginBounds.Width / 2) - 10, e.MarginBounds.Height)
Dim rectRightColumn As New RectangleF( _
(e.MarginBounds.Width / 2) + 110, e.MarginBounds.Top, _
(e.MarginBounds.Width / 2) - 10, e.MarginBounds.Height)
had the rectangle width for the right column occupying the whole page before! *bangs head against wall*
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|