例子
代码如下 |
复制代码 |
using System;
using System.Drawing.Printing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (string item in PrinterSettings.InstalledPrinters)
{
PrinterSettings setting = new PrinterSettings() { PrinterName = item };
textBox1.Text += string.Format(
"Name:\"{0}\", DefaultPrinter:{1}, Valid:{2}\r\n",
setting.PrinterName,
setting.IsDefaultPrinter,
setting.IsValid
);
}
}
}
}
|
好了在这里我并没有做出下拉可选择并显示打印机了,只是一段可以得到打印机的代码并利用from1输出显示了。