how to print Test-page on default Printer?

后端 未结 3 639
误落风尘
误落风尘 2021-01-25 14:40

how to print Test-page on default Printer

using C# Winform Code ?

thank\'s in advance

3条回答
  •  既然无缘
    2021-01-25 15:05

    To generate the built-in Windows test page, you can also use p/invoke against PrintUI.dll. Here's a simple class which lets you do this:

    public static class PrintTestPageHelper
    {
        [DllImport("printui.dll", SetLastError = true, CharSet = CharSet.Unicode)]
        private static extern void PrintUIEntryW(IntPtr hwnd, 
            IntPtr hinst, string lpszCmdLine, int nCmdShow);
    
        /// 
        /// Print a Windows test page.
        /// 
        /// 
        /// Format: \\Server\printer name, for example:
        /// \\myserver\sap3
        /// 
        public static void Print(string printerName)
        {
            var printParams = string.Format(@"/k /n{0}", printerName);
            PrintUIEntryW(IntPtr.Zero, IntPtr.Zero, printParams, 0);
        }
    }
    
    public class Program
    {
    
        static void Main(string[] args)
        {
            PrintTestPageHelper.Print(@"\\printserver.code4life.com\sap3");
    
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
    
    }
    

提交回复
热议问题