#region 交班 /// <summary>
/// 打印交班
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tb_Report_Click(object sender, System.EventArgs e)
{
if(this.arrayList.Count == 0) return;
try
{
PrintDocument pd = new PrintDocument(); 
pd.PrintPage += new PrintPageEventHandler( PrintShift );
pd.Print();
}
catch
{
this.sp_description.Text = "打印失败!请检查打印机是否可用...........";
return;
}
this.sp_description.Text = "请重新登陆系统!..........";
Application.Exit();
} /// <summary>
/// 打印交班单
/// </summary>
/// <param name="sender"></param>
/// <param name="ev"></param>
private void PrintShift(object sender, PrintPageEventArgs ev)
{
Font printFont;
String str;
float yPos       = 0;
int   count      = 0;
float leftMargin = 0; //ev.MarginBounds.Left;
float topMargin  = 0; //ev.MarginBounds.Top; printFont = new Font("黑体", 12); str = "          交  班  单";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
printFont = new Font("新宋体", 10);
count++;  //加一空行 str       = "----------------------------------------";
yPos      = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); //打印当前营业日期
str       = "   " + this.lb_workDate.Text;
yPos      = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); str       = "----------------------------------------";
yPos      = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); str = "      总笔数: " + arrayList.Count.ToString();
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); double allAmount = 0;
foreach(string s in arrayList)
{
allAmount += double.Parse(s);
}
str = "      总金额: " + allAmount.ToString("####0.00") + "元";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++;  //加一空行
str = "      收银员: " + this.User.Fullname;
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++;  //加一空行
str = "      签  章: ________________";
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str , printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); str       = "----------------------------------------";
yPos      = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); str  = "打印时间:"+DateTime.Now.ToString( "yyyy.MM.dd HH:mm:ss" );
yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); //滚动6行
count += 5;
str       = " ";
yPos      = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
}

解决方案 »

  1.   

    using System.Drawing;
    using System.Drawing.Printing;
      

  2.   

    关键是这几句了。
    PrintDocument pd = new PrintDocument(); 
    pd.PrintPage += new PrintPageEventHandler( PrintShift );
    pd.Print();
      

  3.   

    这个没有什么,很简单的,你仔细看看
    就是通过
    ev.Graphics.DrawString ( str, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
    来打印
    str就是你要打印的内容
    printFont是这一行的字体
    leftMargin和yPos是一个坐标,打印该行的起始的坐标
    StringFormat()这个在这里我没有用,你也可以去掉不停的一行一行的打印
    直到结束然后用
    PrintDocument pd = new PrintDocument(); 
    pd.PrintPage += new PrintPageEventHandler( PrintShift );
    pd.Print();来打印
      

  4.   

    yPos = topMargin + ((count++) * printFont.GetHeight(ev.Graphics));
    就是用来计算起始坐标的Y点
    你可以简单的写yPos = 10;
    或者
    yPos = 18;