Imports System.Data
Imports System.Data.OleDb
Public Class frmprintallstudent
Inherits System.Windows.Forms.Form
Dim SQLstat As String
Dim cn As New OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim i As Integer
Dim flaqa As Boolean
Dim q As Integer
Dim dt As New DataTable
Dim currentTime As System.DateTime = System.DateTime.Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New frmprintallstudent
frm.Show()
Me.Hide()
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Declare Local Variable
Dim dialogResult As DialogResult ' DialogResult Is To Get Answer From User
dialogResult = MessageBox.Show("Do You Want To Close This Form?", "Close Form?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dialogResult = dialogResult.Yes Then
Me.Close() ' Terminate This Form
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim printFont As New Font("TIMES NEW ROMAN", 20)
Dim printFont1 As New Font("TIMES NEW ROMAN", 16)
Dim printFont2 As New Font("TIMES NEW ROMAN", 8)
Dim lineHeightSingle As Single = printFont.GetHeight
Dim horizontalPrintLocationsingle As Single = e.MarginBounds.Left
Dim horizontalPrintLocationsingle1 As Single = e.MarginBounds.Right
Dim verticalPrintLocationSingle As Single = e.MarginBounds.Top
Dim head As String = "Music Forest Private Limited"
Dim add As String = "28 Maxwell Road, Unit 02-08"
Dim add2 As String = "Red Dot Traffic, Singapore 069120"
Dim Tel As String = "Tel: (65) 6223 1311"
Dim Fax As String = "Fax: (65) 6223 8588"
Dim Email As String = "Email:musicforest@ob-i.net"
Dim title As String = "List All Students' Detail"
Dim recFound As Boolean = False
Dim da As New OleDb.OleDbDataAdapter
Dim i As Integer
Dim rowIndex As Integer
e.Graphics.DrawString(head, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(add, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(add2, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(Tel, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(Fax, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(Email, printFont, Brushes.SkyBlue, 280, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString(title, printFont, Brushes.Black, 300, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString("________________________________________________________________________________________________________________________", printFont2, Brushes.Black, horizontalPrintLocationsingle, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString("No. ", printFont2, Brushes.Black, horizontalPrintLocationsingle, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString("Student ID", printFont2, Brushes.Black, 140, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString("StudentName", printFont2, Brushes.Black, 240, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString("Gender", printFont2, Brushes.Black, 380, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString("IC No", printFont2, Brushes.Black, 480, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString("Course", printFont2, Brushes.Black, 650, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString("________________________________________________________________________________________________________________________", printFont2, Brushes.Black, horizontalPrintLocationsingle, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=student.mdb;")
cn.Open()
SQLstat = "select * FROM table1 "
da = New OleDbDataAdapter(SQLstat, cn)
da.Fill(dt)
For i = 0 To (dt.Rows.Count - 1)
rowIndex = i
e.Graphics.DrawString(i + 1 & ") ", printFont2, Brushes.Black, horizontalPrintLocationsingle, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(CStr(dt.Rows(rowIndex)("studentID")), printFont2, Brushes.Black, 140, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(CStr(dt.Rows(rowIndex)("StudentName")), printFont2, Brushes.Black, 240, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(CStr(dt.Rows(rowIndex)("Gender")), printFont2, Brushes.Black, 380, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(CStr(dt.Rows(rowIndex)("IC")), printFont2, Brushes.Black, 480, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(CStr(dt.Rows(rowIndex)("course")), printFont2, Brushes.Black, 650, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
Next
e.Graphics.DrawString("________________________________________________________________________________________________________________________", printFont2, Brushes.Black, horizontalPrintLocationsingle, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString("Total Student:", printFont2, Brushes.Black, 660, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
e.Graphics.DrawString(i & " ", printFont2, Brushes.Black, 740, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 1
e.Graphics.DrawString("Printed By:" + currentTime.Date, printFont2, Brushes.Black, 660, verticalPrintLocationSingle)
verticalPrintLocationSingle += lineHeightSingle * 0
Catch ex As Exception
MsgBox("HELP" + ex.ToString, , "Error")
End Try
cn.Close()
End Sub
Private Sub frmprintallstudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Can anyone teach me how to print the detail in second page if the record is too many. Because now i only can printing record in the first page, if record is too many it also no print to the second pages..
i really dont know how to write the coding to let it print to another pages..please help me..thank