public class LocalPrinter
{
private static PrintDocument fPrintDocument = new PrintDocument();
//获取本机默认打印机名称
public static String DefaultPrinter()
{
return fPrintDocument.PrinterSettings.PrinterName;
}
public static List<String> GetLocalPrinters()
{
List<String> fPrinters = new List<String>();
fPrinters.Add(DefaultPrinter()); //默认打印机始终出现在列表的第一项
foreach (String fPrinterName in PrinterSettings.InstalledPrinters)
{
if (!fPrinters.Contains(fPrinterName))
{
fPrinters.Add(fPrinterName);
}
}
return fPrinters;
}
//打开打印机首选项
public static void OpenPrintSettings(string printerName)
{
// 定义打印机名称,可以在打印机首选项中指定
//string printerName = "YourPrinterName";
// 使用 Process 类启动打印机首选项
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "rundll32.exe",
Arguments = "printui.dll,PrintUIEntry /e /n \"" + printerName + "\"",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
Process process = new Process
{
StartInfo = psi
};
process.Start();
process.WaitForExit();
// 处理打印机首选项对话框关闭后的操作,如果需要的话
}
}
C#打开打印机首选项对框 设置打印机
最新推荐文章于 2024-09-12 18:54:58 发布