我想在C#的收据底部添加图片 [英] I want to add image in bottom of my receipt in C#
本文介绍了我想在C#的收据底部添加图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在收据底部的图片框中添加图片,这是我正在尝试的代码,但现在打印带图片的收据
什么我试过了:
private void printreceipt1()
{
PrintDialog printdialog1 = new PrintDialog();
PrintDocument printdocument1 = new PrintDocument();
PaperSize bp = new PaperSize( Custom , 100 , 200 );
printdialog1.Document = printdocument1;
printdocument1.PrintPage + = new PrintPageEventHandler(printdocument1_PrintPage);
printdocument1.DefaultPageSettings.PaperSize = bp;
printdocument1.DefaultPageSettings.PaperSize.Height = 1510 ;
printdocument1.DefaultPageSettings.PaperSize.Width = 320 ;
printdocument1.PrinterSettings.PrinterName = setaluefortextprinter;
// DialogResult result = printdialog23.ShowDialog();
// if(result == DialogResult.OK)
// {
printdocument1.Print();
// }
}
void printdocument1_PrintPage( object sender,PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
字体f = 新字体( Arial , 8 );
float fontHeight = f.GetHeight();
int starto = 30 ;
int startp = 6 ;
int startoo = 180 ;
int startpp = 9 ;
int startX = 10 ;
int startY = 10 ;
int offset = 40 ;
int offset1 = 260 ;
int offset2 = 280 ;
int line = 1 ;
int line1 = 5 ;
int line2 = 6 ;
int line3 = 24 ;
int line4 = 124 ;
int line5 = 32 ;
int line6 = 20 ;
int line7 = 3 ;
int line8 = 6 ;
int line9 = 32 ;
int offset3 = 250 ;
int offset4 = 260 ;
int offset5 = 270 ;
graphics.DrawString(txtDisplay.Text, new 字体( Courier New, 6 ), new SolidBrush( Color.Black),line,line1);
graphics.DrawString(setaluefortext00001name, new 字体( Courier New, 15 ), new SolidBrush(Color.Black),starto ,startp);
graphics.DrawString( ***************** **********, new 字体( Courier New, 6 ), new SolidBrush(Color.Black),line2,line3);
graphics.DrawString(label4.Text, new 字体( Courier New, 6 ), new SolidBrush(Color.Black) ,line8,line9);
// graphics.DrawString(Receipt#:+ label2.Text,new Font(Courier New ,6),新的SolidBrush(Color.Red),line4,line5);
foreach (tblProductEx product in products1)
{
// for(int z = 0; z< dataGridView2.Rows.Count - 1; z ++)
// {
string productDescription = product.productName.PadRight( 30 );
string productTotal = Rs: + string .Format( {0:},product.productPrice);
string prodcutLine = productDescription + productTotal;
graphics.DrawString(prodcutLine,f, new SolidBrush(Color.Black),startX,startY + offset);
offset = offset +( int )fontHeight + 5 ;
// }
}
offset = offset + 20 跨度>;
tblTransaction transaction = new tblTransaction();
transaction.transactionDate = DateTime.Now;
graphics.DrawString( Total To Pay .PadRight( 15 )+ Rs + string .Format( {0:},total1),f , new SolidBrush(Color.Black),startX,startY + offset3);
graphics.DrawString( 谢谢你的到来, .PadRight( 15 )+ string .Format( ),f, new SolidBrush(Color.Black),startX,startY + offset4);
这里我要添加图片 收据graphics.DrawStri
解决方案
所以使用Graphics.DrawImage: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage(v = vs.110)的.aspx [< a href =https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]
i want to add image from picturebox in bottom of my receipt here is the code that i am trying but it's now print receipt with picture
What I have tried:
private void printreceipt1()
{
PrintDialog printdialog1 = new PrintDialog();
PrintDocument printdocument1 = new PrintDocument();
PaperSize bp = new PaperSize("Custom", 100, 200);
printdialog1.Document = printdocument1;
printdocument1.PrintPage += new PrintPageEventHandler(printdocument1_PrintPage);
printdocument1.DefaultPageSettings.PaperSize = bp;
printdocument1.DefaultPageSettings.PaperSize.Height = 1510;
printdocument1.DefaultPageSettings.PaperSize.Width = 320;
printdocument1.PrinterSettings.PrinterName = setaluefortextprinter;
//DialogResult result = printdialog23.ShowDialog();
//if (result == DialogResult.OK)
//{
printdocument1.Print();
//}
}
void printdocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
Font f = new Font("Arial", 8);
float fontHeight = f.GetHeight();
int starto = 30;
int startp = 6;
int startoo = 180;
int startpp = 9;
int startX = 10;
int startY = 10;
int offset = 40;
int offset1 = 260;
int offset2 = 280;
int line = 1;
int line1 = 5;
int line2 = 6;
int line3 = 24;
int line4 = 124;
int line5 = 32;
int line6 = 20;
int line7 = 3;
int line8 = 6;
int line9 = 32;
int offset3 = 250;
int offset4 = 260;
int offset5 = 270;
graphics.DrawString(txtDisplay.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line, line1);
graphics.DrawString(setaluefortext00001name, new Font("Courier New", 15), new SolidBrush(Color.Black), starto, startp);
graphics.DrawString("*****************************************************************", new Font("Courier New", 6), new SolidBrush(Color.Black), line2, line3);
graphics.DrawString(label4.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line8, line9);
//graphics.DrawString("Receipt#:" + label2.Text, new Font("Courier New", 6), new SolidBrush(Color.Red), line4, line5);
foreach (tblProductEx product in products1)
{
//for (int z = 0; z < dataGridView2.Rows.Count - 1; z++)
//{
string productDescription = product.productName.PadRight(30);
string productTotal = "Rs:" + string.Format("{0:}", product.productPrice);
string prodcutLine = productDescription + productTotal;
graphics.DrawString(prodcutLine, f, new SolidBrush(Color.Black), startX, startY + offset);
offset = offset + (int)fontHeight + 5;
//}
}
offset = offset + 20;
tblTransaction transaction = new tblTransaction();
transaction.transactionDate = DateTime.Now;
graphics.DrawString("Total To Pay".PadRight(15) + "Rs " + string.Format("{0:}", total1), f, new SolidBrush(Color.Black), startX, startY + offset3);
graphics.DrawString("Thank You For Coming,".PadRight(15) + string.Format(""), f, new SolidBrush(Color.Black), startX, startY + offset4);
Here i want to add image in receipt graphics.DrawStri
解决方案
So use Graphics.DrawImage: https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage(v=vs.110).aspx[^]
这篇关于我想在C#的收据底部添加图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文