Torna al Thread
Public Sub PrintModCol3(ByVal e As System.Drawing.Printing.PrintPageEventArgs, ByVal dtPrint As DataTable)
Static i As Integer
Static Pagina As Integer
Try
Dim Font1 As New Font("Arial Black", 14)
Dim Font2 As New Font("Arial", 14, FontStyle.Bold)
Dim Font3 As New Font("Arial", 8, FontStyle.Bold)
Dim Font4 As New Font("Arial", 8)
Dim Y As Integer = 280
Dim str As String
e.Graphics.DrawImage(Image.FromFile(Application.StartupPath & "\logo.jpg"), 50, 50, 150, 150)
e.Graphics.DrawString("Telephone Directory on Active Directory", Font1, Brushes.Black, 250, 100)
e.Graphics.DrawString(Date.Today.Date, Font3, Brushes.Black, 250, 140)
e.Graphics.DrawLine(Pens.Red, 50, 200, 785, 200)
e.Graphics.DrawString("User list", Font2, Brushes.Black, 50, 215)
e.Graphics.DrawString("Name", Font3, Brushes.Black, 50, 255)
e.Graphics.DrawString("Surname", Font3, Brushes.Black, 150, 255)
e.Graphics.DrawString("Telephone", Font3, Brushes.Black, 225, 255)
e.Graphics.DrawString("Name", Font3, Brushes.Black, 300, 255)
e.Graphics.DrawString("Surname", Font3, Brushes.Black, 400, 255)
e.Graphics.DrawString("Telephone", Font3, Brushes.Black, 475, 255)
e.Graphics.DrawString("Name", Font3, Brushes.Black, 550, 255)
e.Graphics.DrawString("Surname", Font3, Brushes.Black, 650, 255)
e.Graphics.DrawString("Telephone", Font3, Brushes.Black, 725, 255)
For i = i To i + 52
If i < dtPrint.Rows.Count Then
If i > 0 And i <= 52 Then
If IsDBNull(dtPrint.Rows(i).Item(0)) = False Then
str = dtPrint.Rows(i).Item(0)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 50, Y)
If IsDBNull(dtPrint.Rows(i).Item(1)) = False Then
str = dtPrint.Rows(i).Item(1)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 150, Y)
If IsDBNull(dtPrint.Rows(i).Item(5)) = False Then
str = Right(dtPrint.Rows(i).Item(5), 3)
Else
str = ""
End If
e.Graphics.DrawString((str.PadLeft(Len(str))), Font4, Brushes.Black, 250, Y)
Y = Y + Font4.GetHeight
End If
If i >= 53 And i <= 104 Then
If IsDBNull(dtPrint.Rows(i).Item(0)) = False Then
str = dtPrint.Rows(i).Item(0)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 300, Y)
If IsDBNull(dtPrint.Rows(i).Item(1)) = False Then
str = dtPrint.Rows(i).Item(1)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 400, Y)
If IsDBNull(dtPrint.Rows(i).Item(5)) = False Then
str = Right(dtPrint.Rows(i).Item(5), 3)
Else
str = ""
End If
e.Graphics.DrawString((str.PadLeft(Len(str))), Font4, Brushes.Black, 475, Y)
Y = Y + Font4.GetHeight
End If
If i >= 105 And i <= 156 Then
If IsDBNull(dtPrint.Rows(i).Item(0)) = False Then
str = dtPrint.Rows(i).Item(0)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 550, Y)
If IsDBNull(dtPrint.Rows(i).Item(1)) = False Then
str = dtPrint.Rows(i).Item(1)
Else
str = ""
End If
e.Graphics.DrawString(str, Font4, Brushes.Black, 650, Y)
If IsDBNull(dtPrint.Rows(i).Item(5)) = False Then
str = Right(dtPrint.Rows(i).Item(5), 3)
Else
str = ""
End If
e.Graphics.DrawString((str.PadLeft(Len(str))), Font4, Brushes.Black, 725, Y)
Y = Y + Font4.GetHeight
End If
e.HasMorePages = True
Else
e.HasMorePages = False
End If
Next i
e.Graphics.DrawLine(Pens.Red, 50, 975, 785, 975)
Pagina += 1
e.Graphics.DrawString("Page " & Pagina, Font3, Brushes.Black, 700, 960)
Catch ex As Exception
MsgBox(ex.Message)
End Try
If e.HasMorePages = False Then
i = 0
Pagina = 0
dtPrint.Clear()
End If
End Sub