C# winform代码如何实现设置默认打印机
展开全部
实例化winspool.drv对象,然后调用SetDefaultPrinter方法来设置默认打印机
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
private static extern long SetDefaultPrinter(string pszPrinter);
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
private static extern long SetDefaultPrinter(string pszPrinter);
追问
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
{
public partial class Form1 : Form
{public Form1()
{ InitializeComponent(); }
[DllImport("winspool.drv")]
public static extern bool SetDefaultPrinter(string Name);
private void button1_Click(object sender, EventArgs e) {SetDefaultPrinter("My Microsoft XPS Document Writer");}}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询