现在的位置: 首页 > 综合 > 正文

KFC打印

2013年06月05日 ⁄ 综合 ⁄ 共 2124字 ⁄ 字号 评论关闭
//打印文档,对要打印的每一页都发生一次
        private void pdocFile_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            bool isFirstPage = true;
            int lines = 0;//根据当前页面的内容和字体大小,计算在有效打印范围内可以容纳的行数
            int count = 0;//对行数进行计数
            float left = e.PageSettings.Margins.Left;//打印区域的左边界
            float top = e.PageSettings.Margins.Top;//打印区域的上边界
            float width = e.PageSettings.PaperSize.Width - left - e.PageSettings.Margins.Right;//计算出有效打印区域的宽度
            float height = e.PageSettings.PaperSize.Height - top - e.PageSettings.Margins.Bottom;//计算出有效打印区域的高度
            Font titlefont = new Font("楷体_gb2312", 36);
            Font font = new Font("隶书", 20);
            string s = "";
    
            //画出有效打印区域的边界线
            Pen pen = new Pen(Color.HotPink, 5);
            e.Graphics.DrawLine(pen, new Point((int)left, (int)top), new Point((int)left + (int)width, (int)top));
            e.Graphics.DrawLine(pen, new Point((int)left, (int)top), new Point((int)left, (int)top + (int)height));
            e.Graphics.DrawLine(pen, new Point((int)left + (int)width, (int)top), new Point((int)left + (int)width, (int)top + (int)height));
            e.Graphics.DrawLine(pen, new Point((int)left, (int)top + (int)height), new Point((int)left + (int)width, (int)top + (int)height));

            e.Graphics.DrawString("KFC餐厅购餐小票", titlefont, Brushes.Blue, left + width / 6, top + 5, new StringFormat());

            e.Graphics.DrawString("  日期:" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(), font, Brushes.Blue, left, top + titlefont.GetHeight(e.Graphics), new StringFormat());
            e.Graphics.DrawString("    操作员:1", font, Brushes.Blue, left + width / 2 + 50, top + titlefont.GetHeight(e.Graphics), new StringFormat());
            e.Graphics.DrawString("   餐品名称    单价     数量     总价", font, Brushes.Black, left, top + titlefont.GetHeight(e.Graphics) + font.GetHeight(e.Graphics), new StringFormat());

            lines = ((int)(height - 10 - titlefont.GetHeight(e.Graphics)) - (int)font.GetHeight(e.Graphics)) / (int)font.GetHeight(e.Graphics);
            top = top + 10 + titlefont.GetHeight(e.Graphics) + (int)font.GetHeight(e.Graphics) * 2;
            int i = 0;
            for (i = 0; i < dataset.Tables["SalePrint"].Rows.Count && count < lines; i++)
          

抱歉!评论已关闭.