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
| Imports System.Timers
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Printing
Public Class Service2010
Dim TimerX As System.Timers.Timer = New System.Timers.Timer()
Dim pd As New PrintDocument()
Private Sub pd_PrintPage(sender As Object, ev As System.Drawing.Printing.PrintPageEventArgs)
Try
ev.Graphics.DrawString("Hello", New Font("Arial", 80, FontStyle.Bold), Brushes.Black, 150, 125)
Catch ex As Exception
PrintRapport("pd_PrintPage : " & ex.ToString)
End Try
End Sub
Private Sub OnTimer(sender As Object, e As Timers.ElapsedEventArgs)
Try
pd.PrinterSettings.PrinterName = "HP LaserJet"
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Catch ex As Exception
PrintRapport("OnTimer : " & ex.ToString)
End Try
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
'RequestAdditionalTime(60000) // temps pour le lancement du service
TimerX.Enabled = True
TimerX.Interval = 10000
AddHandler TimerX.Elapsed, AddressOf Me.OnTimer
TimerX.Start()
End Sub
Protected Overrides Sub OnStop()
TimerX.Enabled = False
End Sub
End Class |
Partager