问题描述
我想通过单击按钮为 Windows/系统设置设置默认打印机.我想单击一个按钮并希望出现一个 Windows 对话框,要求用户设置默认打印机.现在我正在为此使用 PrintDialog,但每次单击按钮时它都会更改打印机.我想将所选打印机设置为默认打印机,即使我关闭应用程序也应保持不变.
I want to set a default printer for windows/ system setting on a button click. I want to click on a button and want that a windows dialogue should appear asking user to set a default printer. Right now I am using the PrintDialog for this but it changes the printer every time I click on the button. I want to set the selected printer as a default one that should remain the same even if I close the application as well.
private void PrintSettingsBtn_Click(object sender, EventArgs e)
{
PrintDialog PrintDialog = new PrintDialog();
PrintDialog.ShowDialog();
PrinterName = PrintDialog.PrinterSettings.PrinterName;
}
推荐答案
Try SetDefaultPrinter
Windows API 函数
Try SetDefaultPrinter
Windows API function
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);
见
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162971(v=vs.85).aspxhttp://www.pinvoke.net/default.aspx/winspool/SetDefaultPrinter.html?diff=y
这篇关于使用 c# 为 windows 设置默认打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!