IsPrinterLocked Method

Summary
Determines whether the specified printer is locked.
Syntax
C#
C++/CLI
public bool IsPrinterLocked() 
public: 
bool IsPrinterLocked();  

Return Value

True if the specified printer is locked; otherwise it is false.

Remarks

This method checks if applications were prevented from directly printing to the specified printer.

To lock the specified printer, use the Lock method.

To unlock the specified printer, use the UnLock method.

Example
C#
using Leadtools.Printer; 
using Leadtools; 
 
 
public void PrinterDriverExamples() 
{ 
   InstallPrinter(); 
 
   printer = new Printer("Test LEADTOOLS Printer "); 
 
   if (printer.IsPrinterLocked()) 
   { 
      printer.UnLock("Test Password"); 
   } 
   else 
   { 
      printer.Lock("Test Password"); 
   } 
 
   int iPAPER_USER = 256; 
   PrinterSpecifications myPrinterSpecifications = new PrinterSpecifications(); 
   myPrinterSpecifications.PaperID = iPAPER_USER + 200; 
   myPrinterSpecifications.PaperSizeName = "Custom Paper Name"; 
   myPrinterSpecifications.PaperHeight = 11; 
   myPrinterSpecifications.PaperWidth = 8; 
   myPrinterSpecifications.DimensionsInInches = true; 
   myPrinterSpecifications.PortraitOrient = true; 
   myPrinterSpecifications.MarginsPrinter = "Margins Printer Name"; 
   myPrinterSpecifications.PrintQuality = 300; 
   myPrinterSpecifications.YResolution = 300; 
 
   printer.Specifications = myPrinterSpecifications; 
   printer.UserDefaultSpecifications = myPrinterSpecifications; 
 
   printer.EmfEvent += new EventHandler<EmfEventArgs>(printer_EmfEvent); 
   printer.JobEvent += new EventHandler<JobEventArgs>(printer_JobEvent); 
} 
 
Printer printer; 
 
public void InstallPrinter() 
{ 
   try 
   { 
      string printerName = "Test LEADTOOLS Printer"; 
      string printerPassword = "Test Password"; 
      if (Printer.IsLeadtoolsPrinter(printerName)) 
      { 
         PrinterInfo tmpPrinterInfo = new PrinterInfo(); 
         tmpPrinterInfo.PrinterName = printerName; 
         Printer.UnInstall(tmpPrinterInfo); 
      } 
 
      string documentPrinterRegPath = "SOFTWARE\\LEAD Technologies, Inc.\\22\\Printer\\"; 
      PrinterInfo printerInfo = new PrinterInfo(); 
      printerInfo.MonitorName = printerName; 
      printerInfo.PortName = printerName; 
      printerInfo.ProductName = printerName; 
      printerInfo.PrinterName = printerName; 
      printerInfo.Password = printerPassword; 
      printerInfo.RegistryKey = documentPrinterRegPath + printerName; 
      printerInfo.RootDir = @"C:\LEADTOOLS22\Bin\Common\PrinterDriver"; 
      printerInfo.Url = "https://www.leadtools.com"; 
      printerInfo.PrinterExe = Application.ExecutablePath; 
      printerInfo.AboutString = "LEADTOOLS Printer"; 
      printerInfo.AboutIcon = Path.Combine(LEAD_VARS.ImagesDir, "RasterPro.ico"); 
 
      Printer.Install(printerInfo); 
 
      string strMsg = string.Format("Installation {0} Completed Successfully", printerName); 
      MessageBox.Show(strMsg, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information); 
   } 
   catch (PrinterDriverException ex) 
   { 
      MessageBox.Show(string.Format("Other error: Message:{0}", ex.Message)); 
   } 
} 
 
void printer_EmfEvent(object sender, EmfEventArgs e) 
{ 
   System.IO.File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE1.emf"), e.Stream.ToArray()); 
   Metafile metaFile = new Metafile(e.Stream); 
 
   Image emfImage = metaFile.GetThumbnailImage(metaFile.Width, metaFile.Height, null, IntPtr.Zero); 
   emfImage.Save(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE2.emf")); 
} 
 
void printer_JobEvent(object sender, JobEventArgs e) 
{ 
   string printerName = e.PrinterName; 
   int jobID = e.JobID; 
 
   if (e.JobEventState == EventState.JobStart) 
   { 
      MessageBox.Show(string.Format("Job {0} was started with printer {1}", jobID, printerName)); 
   } 
   else if (e.JobEventState == EventState.JobEnd) 
   { 
      MessageBox.Show(string.Format("Job {0} was ended with printer {1}", jobID, printerName)); 
   } 
   else 
   { 
      printer.CancelPrintedJob(jobID); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Printer Class

Printer Members

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Printer Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.