C # How to obtain the local printer list

Source: Internet
Author: User

Public class localprinter
{
Private Static printdocument fprintdocument = new printdocument ();
/// <Summary>
/// Get the default printer name of the Local Machine
/// </Summary>
Public static string defaultprinter
{
Get {return fprintdocument. printersettings. printername ;}
}
/// <Summary>
/// Obtain the printer list of the local machine. The first item in the list is the default printer.
/// </Summary>
Public static list <string> getlocalprinters ()
{
List <string> fprinters = new list <string> ();
Fprinters. Add (defaultprinter); // default printer always appears in the first item in the list
Foreach (string fprintername in printersettings. installedprinters)
{
If (! Fprinters. Contains (fprintername ))
Fprinters. Add (fprintername );
}
Return fprinters;
}
}

 

Foreach (string fprintername in localprinter. getlocalprinters ())
{
Cbxpos1.items. Add (fprintername );
Cxba41.items. Add (fprintername );
}

Public class localprinter {Private Static printdocument fprintdocument = new printdocument (); /// <summary> /// obtain the default printer name of the Local Machine // </Summary> Public static string defaultprinter {get {return fprintdocument. printersettings. printername ;}/// <summary> /// obtain the printer list of the local machine. The first item in the list is the default printer. /// </Summary> Public static list <string> getlocalprinters () {list <string> fprinters = new list <string> (); fprinters. add (defaultprinter); // The default printer always appears in the first foreach (string fprintername in printersettings. installedprinters) {If (! Fprinters. contains (fprintername) fprinters. add (fprintername);} return fprinters;} foreach (string fprintername in localprinter. getlocalprinters () {cbxpos1.items. add (fprintername); cxba41.items. add (fprintername );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.