如何在C#.NET中設置Windows默認打印機?如何在C#中設置Windows默認打印機?
21
A
回答
14
使用SetDefaultPrinter Windows API。
-2
25
using System;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private void listAllPrinters()
{
foreach (var item in PrinterSettings.InstalledPrinters)
{
this.listBox1.Items.Add(item.ToString());
}
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
string pname = this.listBox1.SelectedItem.ToString();
myPrinters.SetDefaultPrinter(pname);
}
public Form1()
{
InitializeComponent();
listAllPrinters();
}
}
public static class myPrinters
{
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);
}
}
0
下面是如何將其與C#.NET來實現,而不.NET應用程序的範圍內使用Win32API的。應用程序關閉後,Win32API方法保留默認打印機。
using System.Drawing.Printing;
namespace MyNamespace
{
public class MyPrintManager
{
public static PrinterSettings MyPrinterSettings = new PrinterSettings();
public static string Default_PrinterName
{
get
{
return MyPrinterSettings.PrinterName;
}
set
{
MyPrinterSettings.DefaultPageSettings.PrinterSettings.PrinterName = value;
MyPrinterSettings.PrinterName = value;
}
}
}
}
相關問題
- 1. 設置默認打印機
- 2. 如何在wpf中動態設置默認打印機
- 3. 如何在Silverlight中設置默認打印機?
- 4. 如何在eclipse rcp產品中設置默認打印機
- 5. 默認打印機設置被忽略
- 6. iOS AirPrint-設置默認打印機
- 7. 打印到默認的Zebra打印機Windows打印機
- 8. 未設置Windows默認打印機時出現「沒有選擇默認打印機」錯誤
- 9. 如何直接打印斑馬打印機而不將其設置爲使用C#的默認打印機?
- 10. 與改變默認的打印機設置打印PDF文件
- 11. 在C#中的默認打印機無聲打印
- 12. 使用c設置窗口的默認打印機#
- 13. 如何以編程方式設置默認打印機
- 14. 我需要將.emacs打印到默認的Windows打印機中?
- 15. 我可以確定何時在Windows上設置了默認打印機
- 16. 在UWP應用程序中設置默認打印機
- 17. 打印從WebBrowser控件打印到錯誤的打印機後設置默認
- 18. 如何指定打印機以外的默認打印機?
- 19. 當默認打印機是網絡打印機時,Word 2007 Application.ActivePrinter沒有設置
- 20. 將默認打印機設置爲更改名稱的打印機
- 21. 如何更改默認打印機
- 22. 如何在默認打印機上打印測試頁?
- 23. 通過C#在窗口中設置默認打印機的屬性
- 24. c#設置打印機
- 25. 如何在打印時設置打印機設置PDF
- 26. 如何設置在C#中的打印機端口上指定的打印機
- 27. 如何檢查是否有默認打印機(Windows)?
- 28. 如何使用不帶打印機的默認打印機(VB Net)打印PDF
- 29. c#Winform:ReportViewer,直接打印到默認打印機
- 30. 無對話框的鉻打印(默認打印機)Winforms C#
此鏈接已死亡。 – 2017-01-31 21:51:43