c#调用打印机
来源:互联网 发布:域名转出收费 编辑:程序博客网 时间:2024/06/01 19:03
c#调用打印机
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 streamToPrint;
private int leftMargin = 0;
/// <summary>
/// 设置PrintDocument 的相关属性
/// </summary>
/// <param name="str">要打印的字符串</param>
public void print(string str)
{
try
{
streamToPrint = new StringReader(str);
printFont = new Font("宋体", 10);
titleFont = new Font("宋体", 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 yPos = 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 = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, titleFont, Brushes.Black, leftMargin + 10, 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;
}
}
}
- C# 调用打印机
- c# 调用打印机
- c#调用打印机
- C#调用打印机,打印图片
- C#调用打印机打印图片
- C# 调用打印机打印图片
- C#调用打印机,打印图片
- C#调用Windows添加打印机向导
- C#调用Windows添加打印机向导
- [转]C#中调用打印机编程实例
- C# 打印机
- C#调用WIN32API系列二列举局网内共享打印机
- C#调用WIN32API系列二列举局网内共享打印机
- 分享 tsc 条码打印机 打印控件 调用方法 , c# silverlight
- C#调用CodeSoft控制两台打印机打印
- VB调用打印机属性
- 调用打印机,js
- WebService 调用打印机
- grub boot.img makefile源码分析
- MySQL order by 的用法 (Yii篇)
- ACdream
- 列表生成式 是Python内置的非常简单却强大的可以用来创建list的生成式。
- 漫画:高并发下的HashMap
- c#调用打印机
- 如何在非Controller中获取Request和Response:SpringMVC之RequestContextHolder分析
- 前端框架选型
- 容器基础与持续交付
- Oracle相关使用及概念
- 小程序的基础知识
- 代码分支管理
- sql语句group by问题
- (八 附)java并发编程--JVM之指令重排分析