• KFC打印


    //打印文档,对要打印的每一页都发生一次
            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++)
                {

                    DataRow row = dataset.Tables["SalePrint"].Rows[i];
                    if (row[0].ToString().Length > 5)
                    {
                        s = row[0].ToString() + "  " + row[1].ToString() + "  " + row[2].ToString() + "   " + row[3].ToString();
                    }
                    else
                    {
                        s = row[0].ToString() + "        " + row[1].ToString() + "    " + row[2].ToString() + "     " + row[3].ToString();
                    }
                   
                    e.Graphics.DrawString(s, font, Brushes.Black, left, top + count * (int)font.GetHeight(e.Graphics), new StringFormat());
                    count++;
                }
                if (i != dataset.Tables["SalePrint"].Rows.Count)
                {
                    isFirstPage = false;
                    e.HasMorePages = true;  //是否打印附加页
                }
            }

  • 相关阅读:
    Javascript--普通函数调用-涨工资计算函数
    Javascript--运算符判断成绩运算
    Javascript-闰年javascript的判断
    Javascript-逻辑判断或(&&)练习
    Javascript-短路 与(&&)
    UVALive6434_Number Assignment
    HDU4811_Ball
    HDU4810_Wall Painting
    HDU4803_Poor Warehouse Keeper
    HDU4802_GPA
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/1567394.html
Copyright © 2020-2023  润新知