我现在有这里有3台打印机,两台本地,一台局域网,现在想在网页选择某一打印机上通过button或者用DropDownList来选择用什么打印机。

解决方案 »

  1.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Drawing.Printing;
    using System.Runtime.InteropServices;public partial class _Default : System.Web.UI.Page 
    {    [DllImport("winspool.drv")]
        public static extern bool SetDefaultPrinter(string Name);
        
        protected void Page_Load(object sender, EventArgs e)
        {
            foreach (String S in PrinterSettings.InstalledPrinters)
                Response.Write(S+"<br/>");        // 设置第一个为默认打印机
            SetDefaultPrinter(PrinterSettings.InstalledPrinters[0]); 
        }
    }