1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
|
Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Try
Dim yPos As Single = 100
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim drawBoldFont As New Font("Arial", 10, FontStyle.bold)
Dim drawFont As New Font("Arial", 10)
Dim lines as single = 17
Dim spaces as single = 7
Dim header as string
Dim x as integer
dim linesToSkip as integer
'Add the page heading and the time submitted
ev.Graphics.DrawString("THE FOLLOWING REQUEST HAS BEEN SUBMITTED", drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
yPos = yPos + (2*lines)
header = "Department: "
ev.Graphics.DrawString(header, drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
ev.Graphics.DrawString(Me.txtDepartment.Text.Trim, drawFont, Brushes.Black, leftMargin+(len(header)*spaces), yPos, New StringFormat())
yPos = yPos + (1*lines)
header = "Contact Name: "
ev.Graphics.DrawString(header, drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
ev.Graphics.DrawString(Me.txtContact.Text.Trim, drawFont, Brushes.Black, leftMargin+(len(header)*spaces), yPos, New StringFormat())
yPos = yPos + (1*lines)
header = "Phone: "
ev.Graphics.DrawString(header, drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
ev.Graphics.DrawString(Me.txtPhone.Text.Trim, drawFont, Brushes.Black, leftMargin+(len(header)*spaces), yPos, New StringFormat())
yPos = yPos + (2*lines)
'*********All of the above work fine, but when I start getting to the multi-line field below it breaks up
header = "Message: "
ev.Graphics.DrawString(header, drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
x = 1
linesToSkip = 1
dim currentChar As Integer
dim currentLine As Integer
currentChar = 0
currentLine = 1
Dim chars As Integer
Dim foundLineReturn As Boolean
While currentChar < Me.txtMenu.Text.Length
chars = 0
foundLineReturn = False
While chars < 80
If Me.txtMenu.Text.Substring(currentChar + chars, 1) = vbCr Then
foundLineReturn = True
If chars > 1 Then
If currentLine = 1 Then
ev.Graphics.DrawString(Me.txtMenu.Text.Substring(currentChar, chars), drawFont, Brushes.Black, leftMargin + (Len(header) * spaces), yPos, New StringFormat())
Else
ev.Graphics.DrawString(Me.txtMenu.Text.Substring(currentChar, chars), drawFont, Brushes.Black, leftMargin, yPos, New StringFormat())
End If
End If
yPos = yPos + (2 * lines)
chars += 1
currentChar = currentChar + chars
Exit While
Else
chars += 1
End If
End While
If foundLineReturn = False Then
If Me.txtMenu.Text.Substring(currentChar + chars, 1) <> " " And _
Me.txtMenu.Text.Substring(currentChar + chars, 1) <> "-" And _
Me.txtMenu.Text.Substring(currentChar + chars, 1) <> vbLf Then
' As long as the last character is not space or carriage return,
' keep subtracting another character from the text to be printed.
chars = 80
If currentLine = 1 Then chars = chars - 20
While chars > 0 AndAlso _
Me.txtMenu.Text.Substring(currentChar + chars, 1) <> " " AndAlso _
Me.txtMenu.Text.Substring(currentChar + chars, 1) <> vbLf
chars -= 1
End While
chars += 1
End If
If chars = 0 Or chars = 1 Then chars = 80
If currentLine = 1 Then
ev.Graphics.DrawString(Me.txtMenu.Text.Substring(currentChar, chars), drawFont, Brushes.Black, leftMargin + (Len(header) * spaces), yPos, New StringFormat())
Else
ev.Graphics.DrawString(Me.txtMenu.Text.Substring(currentChar, chars), drawFont, Brushes.Black, leftMargin, yPos, New StringFormat())
End If
currentChar = currentChar + chars
currentLine += 1
yPos = yPos + (1 * lines)
End If
End While
yPos = yPos + (1 * lines)
'additionally none of the below prints either
yPos = yPos + (2*lines)
header = "Sent: "
ev.Graphics.DrawString(header, drawBoldFont, Brushes.Black, leftMargin, yPos, New StringFormat())
ev.Graphics.DrawString(Now.ToShortDateString & " - " & Now.ToShortTimeString, drawFont, Brushes.Black, leftMargin+(len(header)*spaces), yPos, New StringFormat())
yPos = yPos + (2*lines)
Catch ex As Exception
HandleError("Error in escort request form PrintPage routine: " & ex.Message, "PrintPage")
End Try
End Sub
|