我想在按钮单击时为Windows /系统设置设置默认打印机.我想点击一个按钮,并希望出现一个Windows对话框,要求用户设置默认打印机.现在我正在使用PrintDialog,但每次点击按钮都会更改打印机.我想将所选的打印机设置为默认打印机,即使我关闭应用程序也应该保持不变.
private void PrintSettingsBtn_Click(object sender, EventArgs e)
{
PrintDialog PrintDialog = new PrintDialog();
PrintDialog.ShowDialog();
PrinterName = PrintDialog.PrinterSettings.PrinterName;
}
Run Code Online (Sandbox Code Playgroud)
尝试SetDefaultPrinterWindows API函数
using System.Runtime.InteropServices;
...
[DllImport("winspool.drv",
CharSet = CharSet.Auto,
SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern Boolean SetDefaultPrinter(String name);
...
SetDefaultPrinter(PrinterName);
Run Code Online (Sandbox Code Playgroud)
看到
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162971(v=vs.85).aspx http://www.pinvoke.net/default.aspx/winspool/SetDefaultPrinter.html? DIFF = Y