C# 调API 打印 ,可以将打印任备添加到打印机列表里 ,但是不打印 ,请高手指点一下

C# 调API 打印 ,可以将打印任备添加到打印机列表里 ,但是不打印 ,请高手指点一下,第1张

 调用打印机好像不用那么麻烦

 //调用打印机

System.Diagnostics.Process p = new System.Diagnostics.Process()

//不现实调用程序窗口,但是对于某些应用无效

p.StartInfo.CreateNoWindow = true

p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden

//采用 *** 作系统自动识别的模式

p.StartInfo.UseShellExecute = true

//指定执行的动作,是打印,即print,打开是 open

p.StartInfo.Verb = "print"

myPrinters.SetDefaultPrinter(pt) //设置默认打印机

p.StartInfo.FileName = 文件路径

p.Start()

或者添加PrintPage事件自己画

调用apid出打印机属性对话框Author:vitoriatangFrom:Internet.NET Framework封装了很多关于打印的对话框,比如说PrintDialog, PageSetupDialog.但是有的时候我们还需要关心打印机属性对话框,那么就可以调用API来解决这个问题。有几个API函数与之相关PrinterPropertiesDocumentPropertiesOpenPrinterClosePrinter逐一介绍 printerproperties显示打印机属性对话框。 documentproperties显示打印机配置对话框。 openprinter打开打印机 closeprinter关闭打印机 在调用printerproperties或者documentproperties的时候,都需要先调用openprinter,并在结束后调用closeprinter。 至于打印机属性和打印机配置有什么不同,就自己领会了。更为详尽的信息可以查阅msdn sample codes:1. 声明API函数 [System.Runtime.InteropServices.DllImportAttribute("winspool.drv", SetLastError = true)] public extern static int DocumentProperties(IntPtr hWnd, // handle to parent windowIntPtr hPrinter, // handle to printer objectstring pDeviceName, // device nameref IntPtr pDevModeOutput, // modified device moderef IntPtr pDevModeInput, // original device modeint fMode) // mode options [System.Runtime.InteropServices.DllImportAttribute("winspool.drv")]public static extern int PrinterProperties(IntPtr hwnd, // handle to parent windowIntPtr hPrinter)// handle to printer object [System.Runtime.InteropServices.DllImportAttribute("winspool.drv", SetLastError = true)]public extern static int OpenPrinter(string pPrinterName, // printer nameref IntPtr hPrinter, // handle to printer objectref IntPtr pDefault) // handle to default printer object. [System.Runtime.InteropServices.DllImportAttribute("winspool.drv", SetLastError = true)]public static extern int ClosePrinter(IntPtr phPrinter)// handle to printer object 2.调用DocumentPropertiesprivate void documentPropButton_Click(object sender, EventArgs e){string printerName = _document.PrinterSettings.PrinterNameif (printerName != null &amp&ampprinterName.Length >0){IntPtr pPrinter = IntPtr.ZeroIntPtr pDevModeOutput = IntPtr.ZeroIntPtr pDevModeInput = IntPtr.ZeroIntPtr nullPointer = IntPtr.ZeroOpenPrinter(printerName, ref pPrinter, ref nullPointer)int iNeeded = DocumentProperties(this.Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, 0)pDevModeOutput = System.Runtime.InteropServices.Marshal.AllocHGlobal(iNeeded)DocumentProperties(this.Handle, pPrinter, printerName, ref pDevModeOutput, ref pDevModeInput, DM_PROMPT)ClosePrinter(pPrinter)}} 3. 调用PrinterPropertiesprivate void printPropButton_Click(object sender, EventArgs e){string printerName = _document.PrinterSettings.PrinterNameif (printerName != null &amp&ampprinterName.Length >0){IntPtr pPrinter = IntPtr.ZeroIntPtr pDevModeOutput = IntPtr.ZeroIntPtr pDevModeInput = IntPtr.ZeroIntPtr nullPointer = IntPtr.ZeroOpenPrinter(printerName, ref pPrinter, ref nullPointer)int iNeeded = PrinterProperties(this.Handle, pPrinter)ClosePrinter(pPrinter)}}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11729837.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存