public static void printe_receipt(PrintPageEventArgs e)
{
lowtax = 0;
hightax = 0;
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
e.Graphics.DrawString("Count", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString("FoodName", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 100;
e.Graphics.DrawString("Mark", new Font("verdana", 7, FontStyle.Regular), Brushes.Black, x, y);
x = x + 80;
e.Graphics.DrawString("Perp", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
x = x + 50;
e.Graphics.DrawString("Tolp", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
y = y + 20;
x = 2;
for (int j = 0; j < ds.Tables["tb"].Rows.Count; j++)//行循环
{
string dishname1;
account = ds.Tables["tb"].Rows[j][0].ToString();//每行第一列的字串参数
price = ds.Tables["tb"].Rows[j][3].ToString();
if (price != null)
{
if (account == "└→")
{
account = "0.0";
}
tolprice = (Convert.ToDouble(price) * Convert.ToDouble(account)).ToString("f2");
}
if (account == "0.0" || account == "└→")// 为“0.0”则表示为特殊行
{
account = "→";
price = "";
tolprice = "";
}
dishname1 = ds.Tables["tb"].Rows[j][1].ToString(); string group = ds.Tables["tb"].Rows[j][7].ToString();
if (dishname1.Length > 112)
{
dishname = dishname1.Substring(0, 11) + "...";
}
else
{
dishname = dishname1;
}
= ds.Tables["tb"].Rows[j][2].ToString();
pertax =Convert.ToDecimal( ds.Tables["tb"].Rows[j][6].ToString());
parameter.prints.totaleprice = ds.Tables["tb"].Rows[j][4].ToString();
e.Graphics.DrawString(account, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString(dishname, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 100;
e.Graphics.DrawString(, new Font("verdana", 5, FontStyle.Regular), Brushes.Black, x, y);
x = x + 80;
e.Graphics.DrawString(price, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
x = x + 50;
e.Graphics.DrawString(tolprice, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
y = y + 15;
x = 2;
if (group == "drink")
{
hightax = hightax + pertax*Convert.ToDecimal(account);
}
else if (group == "food" & account != "→")
{
lowtax = lowtax + pertax * Convert.ToDecimal(account);
}
}
string line9 = "Totaal" + " €";
string line = "-----------------------------------------------------------";
string lowtax1 = Math.Round(lowtax, 2).ToString();
string hightax1 = Math.Round(hightax, 2).ToString();
string line10 = "BTW(" + parameter.lowincl.ToString() + ") €";
string line11 = "BTW(" + parameter.highincl.ToString() + ") €";
e.Graphics.DrawString(line, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y);
y = y + 15;
e.Graphics.DrawString(line9, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(parameter.prints.totaleprice, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
y = y + 15;
e.Graphics.DrawString(line10, new Font("verdana", 6, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(lowtax1, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
y = y + 15;
e.Graphics.DrawString(line11, new Font("verdana", 6, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(hightax1, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
}//发票
我用e.Graphics.DrawString画好的一个页面,在这个方法里。 我能否一行行将它打印出来?想用如下的逐行打印,但不知道怎么去一行行读出自己刚才那个方法里画的。
private void printDocument_PrintPage(object sender,PrintPageEventArgs e) { Graphics g = e.Graphics; //获得绘图对象 float linesPerPage = 0; //页面的行号 float yPosition = 0; //绘制字符串的纵向位置 int count = 0; //行计数器 float leftMargin = e.MarginBounds.Left; //左边距 float topMargin = e.MarginBounds.Top; //上边距 string line = null; 行字符串 Font printFont = this.textBox.Font; //当前的打印字体 SolidBrush myBrush = new SolidBrush(Color.Black);//刷子 linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数 //逐行的循环打印一页 while(count < linesPerPage && ((line=lineReader.ReadLine()) != null)) { yPosition = topMargin + (count * printFont.GetHeight(g)); g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat()); count++; } //如果本页打印完成而line不为空说明还有没完成的页面这将触发下一次的打印事件在下一次的打印中lineReader会 //自动读取上次没有打印完的内容因为lineReader是这个打印方法外的类的成员它可以记录当前读取的位置 if(line != null) e.HasMorePages = true; else e.HasMorePages = false; }
{
lowtax = 0;
hightax = 0;
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
e.Graphics.DrawString("Count", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString("FoodName", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 100;
e.Graphics.DrawString("Mark", new Font("verdana", 7, FontStyle.Regular), Brushes.Black, x, y);
x = x + 80;
e.Graphics.DrawString("Perp", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
x = x + 50;
e.Graphics.DrawString("Tolp", new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
y = y + 20;
x = 2;
for (int j = 0; j < ds.Tables["tb"].Rows.Count; j++)//行循环
{
string dishname1;
account = ds.Tables["tb"].Rows[j][0].ToString();//每行第一列的字串参数
price = ds.Tables["tb"].Rows[j][3].ToString();
if (price != null)
{
if (account == "└→")
{
account = "0.0";
}
tolprice = (Convert.ToDouble(price) * Convert.ToDouble(account)).ToString("f2");
}
if (account == "0.0" || account == "└→")// 为“0.0”则表示为特殊行
{
account = "→";
price = "";
tolprice = "";
}
dishname1 = ds.Tables["tb"].Rows[j][1].ToString(); string group = ds.Tables["tb"].Rows[j][7].ToString();
if (dishname1.Length > 112)
{
dishname = dishname1.Substring(0, 11) + "...";
}
else
{
dishname = dishname1;
}
= ds.Tables["tb"].Rows[j][2].ToString();
pertax =Convert.ToDecimal( ds.Tables["tb"].Rows[j][6].ToString());
parameter.prints.totaleprice = ds.Tables["tb"].Rows[j][4].ToString();
e.Graphics.DrawString(account, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 50;
e.Graphics.DrawString(dishname, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y);
x = x + 100;
e.Graphics.DrawString(, new Font("verdana", 5, FontStyle.Regular), Brushes.Black, x, y);
x = x + 80;
e.Graphics.DrawString(price, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
x = x + 50;
e.Graphics.DrawString(tolprice, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, x, y, drawFormat);
y = y + 15;
x = 2;
if (group == "drink")
{
hightax = hightax + pertax*Convert.ToDecimal(account);
}
else if (group == "food" & account != "→")
{
lowtax = lowtax + pertax * Convert.ToDecimal(account);
}
}
string line9 = "Totaal" + " €";
string line = "-----------------------------------------------------------";
string lowtax1 = Math.Round(lowtax, 2).ToString();
string hightax1 = Math.Round(hightax, 2).ToString();
string line10 = "BTW(" + parameter.lowincl.ToString() + ") €";
string line11 = "BTW(" + parameter.highincl.ToString() + ") €";
e.Graphics.DrawString(line, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 0, y);
y = y + 15;
e.Graphics.DrawString(line9, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(parameter.prints.totaleprice, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
y = y + 15;
e.Graphics.DrawString(line10, new Font("verdana", 6, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(lowtax1, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
y = y + 15;
e.Graphics.DrawString(line11, new Font("verdana", 6, FontStyle.Regular), Brushes.Black, 120, y);
e.Graphics.DrawString(hightax1, new Font("verdana", 8, FontStyle.Regular), Brushes.Black, 250, y, drawFormat);
}//发票
我用e.Graphics.DrawString画好的一个页面,在这个方法里。 我能否一行行将它打印出来?想用如下的逐行打印,但不知道怎么去一行行读出自己刚才那个方法里画的。
private void printDocument_PrintPage(object sender,PrintPageEventArgs e) { Graphics g = e.Graphics; //获得绘图对象 float linesPerPage = 0; //页面的行号 float yPosition = 0; //绘制字符串的纵向位置 int count = 0; //行计数器 float leftMargin = e.MarginBounds.Left; //左边距 float topMargin = e.MarginBounds.Top; //上边距 string line = null; 行字符串 Font printFont = this.textBox.Font; //当前的打印字体 SolidBrush myBrush = new SolidBrush(Color.Black);//刷子 linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数 //逐行的循环打印一页 while(count < linesPerPage && ((line=lineReader.ReadLine()) != null)) { yPosition = topMargin + (count * printFont.GetHeight(g)); g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat()); count++; } //如果本页打印完成而line不为空说明还有没完成的页面这将触发下一次的打印事件在下一次的打印中lineReader会 //自动读取上次没有打印完的内容因为lineReader是这个打印方法外的类的成员它可以记录当前读取的位置 if(line != null) e.HasMorePages = true; else e.HasMorePages = false; }
解决方案 »
- ButtonField获取GridView一行的值
- c# 优化SQL语句还是优化程序代码
- c#winform显示进度条问题
- C#的sqlDataAdapter1.Fill();的问题。
- C#奇怪的内存申请问题(求助)
- 扩展名为CS的文件图标都换成了网页浏览时的图标,该怎么办?
- 关于c#通过oracle8.17的存储过程操作blob字段的问题,哪位高手帮忙解答?!!!!
- [最后20分,全给] webForm页面生成后__doPostBack函数下的theform = document._ctl0:Form1 报错!
- SQL数据库中如何存储pdf文件?如何读取?
- windows 上c#的性能和java的性能比较
- reportViewer1 打印时 显示句柄无效 是什么原因造成的?谁遇到过这种问题?
- 相关mvc的简单问题
private void printDocument_PrintPage(object sender,PrintPageEventArgs e) {
Graphics g = e.Graphics; //获得绘图对象
float linesPerPage = 0; //页面的行号
float yPosition = 0; //绘制字符串的纵向位置
int count = 0; //行计数器
float leftMargin = e.MarginBounds.Left; //左边距
float topMargin = e.MarginBounds.Top; //上边距
string line = null; 行字符串
Font printFont = this.textBox.Font; //当前的打印字体
SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的数
//逐行的循环打印一页
while(count < linesPerPage && ((line=lineReader.ReadLine()) != null)) { yPosition = topMargin + (count * printFont.GetHeight(g));
g.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
count++;
}
//如果本页打印完成而line不为空说明还有没完成的页面这将触发下一次的打印事件在下一次的打印中lineReader会
//自动读取上次没有打印完的内容因为lineReader是这个打印方法外的类的成员它可以记录当前读取的位置
if(line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}