Print1 Project (printing.ppt is the accompanying PowerPoint)
Public Class
frmPrint
Inherits
System.Windows.Forms.Form
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuExit.Click
Me.Close()
End
Sub
Private Sub mnuColorFont_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles mnuColorFont.Click
If dlgColor.ShowDialog() =
DialogResult.OK Then
lblTest.ForeColor = dlgColor.Color
End If
End Sub
Private Sub mnuColorBack_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles mnuColorBack.Click
If dlgColor.ShowDialog() =
DialogResult.OK Then
txtTest.BackColor = dlgColor.Color
End If
End Sub
Private Sub mnuFont_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
mnuFont.Click
If dlgFont.ShowDialog() =
DialogResult.OK Then
lblTest.Font = dlgFont.Font
End If
End Sub
Private Sub mnuPrintDocument_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
mnuPrintDocument.Click
pdPrint.Print()
End Sub
Private Sub pdPrint_PrintPage(ByVal sender
As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs)
Handles pdPrint.PrintPage
e.Graphics.DrawString(txtTest.Text, New Font("Arial", 14, FontStyle.Regular), Brushes.Black,
10, 10)
End Sub
End Class
Printrpt Project
Public Class
frmPrintRpt
Inherits System.Windows.Forms.Form
Dim
stuArray(5) As StudentInfo
Private Sub frmPrintRpt_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
stuArray(0).stuId = 111
stuArray(0).stuName = "John Doe "
stuArray(0).stuMajor = "CI"
stuArray(0).stuGPA = 3.2
stuArray(1).stuId = 123
stuArray(1).stuName = "Susan French"
stuArray(1).stuMajor = "CI"
stuArray(1).stuGPA = 3.6
stuArray(2).stuId = 134
stuArray(2).stuName = "Linda Costa "
stuArray(2).stuMajor = "BU"
stuArray(2).stuGPA = 3.2
stuArray(3).stuId = 222
stuArray(3).stuName = "David Sousa "
stuArray(3).stuMajor = "CI"
stuArray(3).stuGPA = 3.6
stuArray(4).stuId = 234
stuArray(4).stuName = "Ann Ames "
stuArray(4).stuMajor = "CI"
stuArray(4).stuGPA = 4.0
stuArray(5).stuId = 245
stuArray(5).stuName = "Jake Smith "
stuArray(5).stuMajor = "CI"
stuArray(5).stuGPA = 3.85
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnPrint.Click
pdPrint.Print()
End Sub
Private Sub pdPrint_PrintPage(ByVal sender
As System.Object, ByVal
e As System.Drawing.Printing.PrintPageEventArgs)
Handles pdPrint.PrintPage
Dim ct As Integer
Dim wkVert As Integer
Dim totStudents As Integer
'Print the Report Header
e.Graphics.DrawString("Student Report", New Font("Courier New", 16,
FontStyle.Bold), _
Brushes.Black, 275, 50)
'Print the Date Header
e.Graphics.DrawString("Date: " &
Now.ToString, _
New Font("Courier
New", 10, FontStyle.Bold), Brushes.Black, 400, 75)
'Print the Column Header
e.Graphics.DrawString(String.Format("{0,
10}{1, 30}{2, 10}{3, 10}", _
"ID", "NAME", "MAJOR",
"GPA"), New Font("Courier
New", 12, FontStyle.Bold), _
Brushes.Black, 10, 100)
'Print Detail Lines
wkVert = 150
For ct = 0 To 5
e.Graphics.DrawString(String.Format("{0,
10}{1, 30}{2, 10}{3, 10}", _
stuArray(ct).stuId, stuArray(ct).stuName,
stuArray(ct).stuMajor, _
stuArray(ct).stuGPA), New
Font("Courier New", 12, FontStyle.Regular), _
Brushes.Black, 10, wkVert)
totStudents = totStudents + 1
wkVert = wkVert + 15
Next
'Print the total line
wkVert = wkVert + 15
e.Graphics.DrawString("Total Number of Students:
" & totStudents, _
New Font("Courier
New", 12, FontStyle.Bold), Brushes.Black, 10, wkVert)
End Sub
End Class