http://www.it610.com/article/1490591.htm


c#打印机设置,取得打印机列表及相应打印机的所有纸张格式

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace PrintDemo
{

    /// <summary>
    /// 开发者:无名剑
    /// 网站:www.west163.net
    /// QQ:16349023
    /// Email:admin@xo68.com,admin@west163.net
    /// </summary>

    public partial class Form1 : XoExpress.SkinForm.SkinForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            PrintDocument prtdoc = new PrintDocument();
            string strdefaultprinter = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名
            foreach (string strprinter in PrinterSettings.InstalledPrinters)

            //在列表框中列出所有的打印机,
            {
                listBoxEx1.Items.Add(strprinter);
                if (strprinter == strdefaultprinter)//把默认打印机设为缺省值
                {
                    listBoxEx1.SelectedIndex = listBoxEx1.Items.IndexOf(strprinter);
                }
            } 
        }

        private void listBoxEx1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBoxEx2.Items.Clear();
            PrintDocument prtdoc = new PrintDocument();
            prtdoc.PrinterSettings.PrinterName = listBoxEx1.Text;
            foreach (PaperSize ps in prtdoc.PrinterSettings.PaperSizes)
            {
                listBoxEx2.Items.Add(ps.PaperName);
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("IEXPLORE.EXE","http://www.west163.net");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://blog.csdn.net/nnsword");

        }
    }
}






本文转载:CSDN博客