private void _miInstallPrinter_Click(object sender, EventArgs e) { try { FrmInstallPrinter frmInstallPrinter = new FrmInstallPrinter(); DialogResult dialogResult = frmInstallPrinter.ShowDialog(); if (dialogResult == DialogResult.OK) { string newPrinterName = frmInstallPrinter.PrinterName; string newPrinterPassword = frmInstallPrinter.PrinterPassword; bool bSuccess = PrintingUtilities.InstallNewPrinter(newPrinterName, newPrinterPassword); if (bSuccess) { _currentPrinterName = newPrinterName; SetCurrentPrinter(); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void _btnInstallNewPrinter_Click(object sender, EventArgs e) { try { FrmInstallPrinter frmInstallPrinter = new FrmInstallPrinter(); DialogResult dialogResult = frmInstallPrinter.ShowDialog(); if (dialogResult == DialogResult.OK) { Cursor = Cursors.WaitCursor; string newPrinterName = _printerName = frmInstallPrinter.PrinterName; string newPrinterPassword = frmInstallPrinter.PrinterPassword; PrintingUtilities.InstallNewPrinter(newPrinterName, newPrinterPassword); _printerName = newPrinterName; FillLeadtoolsPrintersList(); } } catch (Exception Ex) { MessageBox.Show(Ex.ToString(), "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor = Cursors.Default; } }
private void FillLeadtoolsPrintersList() { try { _cmbPrintersList.Items.Clear(); _cmbPrintersList.Items.AddRange(PrintingUtilities.GetLeadtoolsPrintersList()); _cmbPrintersList.SelectedIndex = 0; EnableControls(); } catch (Exception Ex) { MessageBox.Show(Ex.ToString(), "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
internal static bool InstallNewPrinter(string printerName, string printerPassword) { try { if (IsPrinterExist(printerName)) { string errorMessage = "Duplicated printer name. Please enter another name."; MessageBox.Show(errorMessage, "LEADTOOLS C# Print to PACS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } else { #if LTV16_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\Printer\"; #endif #if LTV17_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\17\Printer\"; #endif #if LTV175_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\17.5\Printer\"; #endif #if LTV18_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\18\Printer\"; #endif #if LTV19_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\19\Printer\"; #endif #if LTV20_CONFIG string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\20\Printer\"; #endif if (Environment.OSVersion.Version.Major >= 6 && !PrintingUtilities.IsUserAnAdmin()) { //On operating system vista or upper, demo requires to be ran with elevated rights return(false); } PrinterInfo printerInfo = new PrinterInfo(); printerInfo.PortName = printerName; printerInfo.MonitorName = printerName; printerInfo.ProductName = printerName; printerInfo.PrinterName = printerName; printerInfo.Password = printerPassword; printerInfo.RegistryKey = documentPrinterRegPath + printerName; printerInfo.RootDir = GetPrinterPath(documentPrinterRegPath); printerInfo.Url = "https://www.leadtools.com/support/default.htm"; printerInfo.PrinterExe = Application.ExecutablePath; //printerInfo.AboutIcon = System.IO.Path.Combine(Leadtools.Demos.DemosGlobal.ImagesFolder, "PrinterDriver.ico"); printerInfo.AboutString = "LEADTOOLS C# Print to PACS"; //Function Requires administrative rights Printer.Install(printerInfo); return(true); } } catch { return(false); } }
private void FillLeadtoolsPrintersList() { string setupPrinter = string.Empty; if (Is64Bit()) { setupPrinter = "LEADTOOLS .NET Printer 64-bit"; } else { setupPrinter = "LEADTOOLS .NET Printer 32-bit"; } #if LTV20_CONFIG if (Is64Bit()) { setupPrinter = "LEADTOOLS 20 .NET Printer 64-bit"; } else { setupPrinter = "LEADTOOLS 20 .NET Printer 32-bit"; } #endif try { _cmbPrintersList.Items.Clear(); _cmbPrintersList.Items.AddRange(PrintingUtilities.GetLeadtoolsPrintersList()); if (_cmbPrintersList.Items.Count > 0) { if (_printerName != string.Empty) { _cmbPrintersList.Text = _printerName; } else { _cmbPrintersList.SelectedIndex = 0; } if (_printerName == string.Empty) { for (int i = 0; i < _cmbPrintersList.Items.Count; i++) { if ((_cmbPrintersList.Items[i] as string).ToLower() == setupPrinter.ToLower()) { _cmbPrintersList.SelectedIndex = i; } } } } else { string errorMessage = "No printers are available."; MessageBox.Show(errorMessage, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } EnableControls(); } catch (Exception Ex) { MessageBox.Show(Ex.ToString(), "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }