请问如何以编程的方式设置系统打印机的各种属性,如“打印首选项”中的“方向”,“高级”中的“纸张规格”。这些设置,一般都是通过人工方式,在操作系统的打印机管理中完成的。现在希望能够以程序进行操作,希望大家指点,谢谢。

解决方案 »

  1.   

    不用API,C#自定义 PrinterSettings就可以了.
      

  2.   

    这个还用得着用API吗?
    PrintDocument对象的DefaultSetting属性里设置就可以了
      

  3.   

    看看这个行么
    [DllImport("shell32.dll", CharSet=CharSet.Auto)]
    public static extern Int32 SHInvokePrinterCommand(
    IntPtr hwnd,// Handle of the window that will be used as the parent of any windows 
    // or dialog boxes that are created during the operation.
    UInt32 uAction, // A value that determines the type of printer operation that will be 
    // performed.
    [MarshalAs(UnmanagedType.LPWStr)]
    String lpBuf1, // Address of a null_terminated string that contains additional 
    // information for the printer command. 
    [MarshalAs(UnmanagedType.LPWStr)]
    String lpBuf2, // Address of a null-terminated string that contains additional
    // information for the printer command. 
    Int32 fModal); //  value that determines whether SHInvokePrinterCommand should return
    // after initializing the command or wait until the command is completed.
      

  4.   

    那就程序关闭之前把PrintDocument.DefaultSetting保存下来,
    下次程序启动是再设置打印属性就可以了。