PrintDocument实例的 DefaultPageSettings 属性 可以设置;
之后Print()直接打印
之后Print()直接打印
解决方案 »
- 时间问题,怎么求出当前系统时间前5分钟的时间
- 求AnkhSvn-2.0.6347.433 简体语言包
- 请教个webservice路径的问题
- 何时该用Get和Set方法,何时该用Property
- 【求助】从 html 中上传文件到 aspx 文件中,如何实现文件的捕获与存储?
- 免费送 分了 进了啊, C# SERVER 的,
- 小弟无才,望各位大侠求救!!!刚接触移动开发,求解插表问题!
- 请教各位大牛啊?
- 怎样实现在搜索结果中继续查找
- 我的投诉之路 -- .net beta1给我带来的烦恼
- 刚由Java转学C# 还请指教 一个简单的windows窗体程序
- gridview高级应用 !!!!!!!!来看看问题,绝对你没遇到过..!!!!!!
using System.Configuration;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;namespace WinUI.BusinessManage
{
/// <summary>
/// 打印方法
/// </summary>
public class Printf
{
public Printf()
{
//
// TODO: 在此处添加构造函数逻辑
//
}private string[] printString =null;private string imagePath = @"";private Font _font = new Font("宋体", 10);private int xPoint=0;private int yPoint=0;private float[] x=null;private float[] y=null;private Color _color= Color.Black;private int pageCount = 1;private int pagePos=0;//分页计数器private int iPos=0;//内容计数器private int iCount=0;//每一页打印内容数// private float _top=0;
// private float _left=0;
private float _top=float.Parse(ConfigurationSettings.AppSettings.Get("PrintTop"));
private float _left=float.Parse(ConfigurationSettings.AppSettings.Get("PrintLeft"));private float drawImageWidth=20;private float drawImageHeight=28;/// <summary>
/// 图片路径
/// </summary>
public string ImagePath
{
set{imagePath=value;}
get{return imagePath;}
}/// <summary>
/// 字体
/// </summary>
public Font Fonts
{
set{_font=value;}
get{return _font;}
}/// <summary>
/// 字体颜色
/// </summary>
public string[] PrintString
{
set{ printString=value;}
get{return printString;}
}/// <summary>
/// 定点打印X坐标
/// </summary>
public float[] X
{
set{ x=value;}
get{return x;}
}/// <summary>
/// 定点打印Y坐标
/// </summary>
public float[] Y
{
set{ y=value;}
get{return y;}
}/// <summary>
/// 字体颜色
/// </summary>
public Color FontColor
{
set{ _color=value;}
get{return _color;}
}/// <summary>
/// 打印页数
/// </summary>
public int PageCount
{
set{ pageCount=value;}
get{return pageCount;}
}/// <summary>
/// 上边距
/// </summary>
public float Top
{
set{ _top=value;}
get{return _top;}
}/// <summary>
/// 左边距
/// </summary>
public float Left
{
set{ _left=value;}
get{return _left;}
}/// <summary>
/// 打印图片宽度
/// </summary>
public float DrawImageWidth
{
set{ drawImageWidth=value;}
get{return drawImageWidth;}
}/// <summary>
/// 打印图片高度
/// </summary>
public float DrawImageHeight
{
set{ drawImageHeight=value;}
get{return drawImageHeight;}
}/// <summary>
/// 定点打印
/// </summary>
public void PrintFixedPoint()
{
PrintDocument MyPrintDC = new PrintDocument();
PrintDialog MyPrintDg = new PrintDialog(); //创建打印对话框
MyPrintDg.Document = MyPrintDC;
if (MyPrintDg.ShowDialog() == DialogResult.OK)
{
try
{
iCount=printString.Length/pageCount;MyPrintDC.PrintPage += new PrintPageEventHandler(PrintFixedPointEvent);
MyPrintDC.Print();
}
catch
{ //停止打印
MyPrintDC.PrintController.OnEndPrint(MyPrintDC, new PrintEventArgs());
}
}
}/// <summary>
/// 执行定点打印操作
/// </summary>
/// <param name="sender"> </param>
/// <param name="e"> </param>
private void PrintFixedPointEvent(object sender, PrintPageEventArgs e)
{
if(imagePath!="")
DrawImagePoint(sender, e);
Graphics MyGraphics = e.Graphics;
float x, y;
if((pageCount>=1) && (printString!=null) )
{
if(printString.Length>0)
if(printString[0]!=null)
{
pagePos++;for(int i=iPos;i <iCount;i++)
{
x = _left*40 + X[i]*40;
y = _top*40 + Y[i]*40;
MyGraphics.DrawString(printString[i], _font, new SolidBrush(_color), x, y, new StringFormat());
}if(pagePos <pageCount)
{
iPos=iCount;
iCount=iCount+(printString.Length/pageCount);
e.HasMorePages = true;
}
else
e.HasMorePages=false;
}
}
}/// <summary>
/// 画图事件方法
/// </summary>
/// <param name="sender"> </param>
/// <param name="e"> </param>
private void DrawImagePoint(object sender, PrintPageEventArgs e)
{
if(!System.IO.File.Exists(imagePath))
return;
Image newImage = Image.FromFile(imagePath);
//Point ulCorner = new Point(xPoint, yPoint);
e.Graphics.DrawImage(newImage, xPoint, yPoint,drawImageWidth*40,drawImageHeight*40);
}/// <summary>
///打印设置
/// </summary>
public void PrintSetup()
{
PrintDocument MyPrintDC = new PrintDocument();
PageSetupDialog MyPageSetupDg = new PageSetupDialog();
MyPageSetupDg.Document = MyPrintDC;
try
{
MyPageSetupDg.ShowDialog();
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}}
}