PrinterMonitorComponent

The PrinterMonitorComponent allows you to set one or more printers to monitor and raises events in response to events which occur on these printers. Events include a new job being added, pages being printed, job settings changes and a job being deleted from the print queue.


Code example (VB.NET)

    Private WithEvents pmon As New PrinterMonitorComponent

    Public Sub New()
        MyBase.New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Monitor all the installed printers 
        For Each p As String In System.Drawing.Printing.PrinterSettings.InstalledPrinters
            pmon.AddPrinter(p)
            pmon.PrinterInformation(p).PauseAllNewJobs = False
        Next p

    End Sub

    Private Sub pmon_JobAdded(ByVal sender As Object, ByVal e As PrintJobEventArgs) Handles pmon.JobAdded

        With CType(e, PrintJobEventArgs)
            Trace.WriteLine("New job added " & .PrintJob.UserName)
        End With

    End Sub

Events

JobAdded - Raised when a new print job is added to a printer queue
JobWritten - Raised when a job is written to on one of the print spool queues being monitored
JobDeleted - Raised when a print job is removed from the queue - either deleted by the user or printed by the printer
JobSet - Raised when a job's properties are changed in one of the print spool queues being monitored
PrinterInformationChanged - Raised when the settings on the printer being monitored change

Properties

Monitoring (Boolean) - True if the component is monitoring any printers
DeviceName (String) - The name of the printer to monitor. If multiple printers are to be monitored then the AddPrinter method is used instead
PrintJobs (PrintJobCollection) - The collection of print jobs in the queue of the named device
PrinterInformation - The printer settings of the named device
JobCount (Int32) - The number of print jobs in the queue of the named device

Methods

AddPrinter - Adds a named printer to the collection of printers to monitor
RemovePrinter - Removes a named printer from the collection of printers being monitored
Disconnect - Stops all printer monitoring

Other settings

ComponentTraceSwitch - Controls the level of trace information emmitted from the component

Last edited Sep 5, 2014 at 7:57 AM by Merrion, version 4

Comments

Merrion Feb 21, 2008 at 8:40 PM 
C# code example wanted - any volunteers?