C # Implementing Printer Capabilities

Source: Internet
Author: User

C # Call Printer
2011-12-13 17:18:00| Category: C # | Tags: calling printer
| report
| font size
Subscription
Download Lofter Client
Using system;using system.collections.generic;using system.text;using system.drawing;using System.IO;using System.Windows.Forms;
Namespace ty_classlibrary{public class Printer {private font printfont; private font titlefont; private StringReader str Eamtoprint; private int leftMargin = 0;
<summary>///Set PrintDocument Properties///</summary>//<param name= "str" > string to print </param> public void print (string str) {try {streamtoprint = new StringReader (str); printfont = new Font ("Arial", "Ten"); Titlefont = n EW Font ("Song Body", 15); System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument (); Pd. Printersettings.printername = "Smartprinter"; Pd. DocumentName = PD. PrinterSettings.MaximumCopies.ToString (); Pd. PrintPage + = new System.Drawing.Printing.PrintPageEventHandler (this.pd_printpage); Pd. Printcontroller = new System.Drawing.Printing.StandardPrintController (); Pd. Print (); } catch (Exception ex) {MessageBox.Show (ex. ToString ()); } }
private void pd_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs ev) {float linesperpage = 0; float YP OS = 0; int count = 0; float leftMargin = This.leftmargin; float TopMargin = 0; String line = null; linesPerPage = ev. Marginbounds.height/printfont.getheight (EV. Graphics); while (Count < linesPerPage && (line = Streamtoprint.readline ()) = null)) {if (count = = 0) {YPos = Topmargi n + (printfont.getheight (EV). Graphics)); Ev. Graphics.DrawString (line, Titlefont, Brushes.black, LeftMargin + ten, YPos, New StringFormat ()); } else {YPos = TopMargin + (count * printfont.getheight (EV). Graphics)); Ev. Graphics.DrawString (line, Printfont, Brushes.black, LeftMargin, YPos, New StringFormat ()); } count++; } if (line! = null) ev. HasMorePages = true; else EV. HasMorePages = false;
}}} Close Up

C # Implementing Printer Capabilities

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.