J'ai du mal à imprimer un reçu d'une manière acceptable pour une application winforms sur laquelle je travaille. Je joins mon code, le reçu que j'imprime et une autre image d'un reçu que je veux imprimer quelque chose comme ça.
voici mon code
private void printready()
{
string welcome = "Thank You For Visiting Dulabk";
string InvoiceNo = txtInvoiceNo.Text;
decimal gross = Convert.ToInt32(txtGross.Text);
decimal net = Convert.ToInt32(txtNet.Text);
decimal discount = gross - net;
string InvoiceDate = dateTimePicker1.Value.ToLongDateString();
int lineHeight = 20;
int supplementaryLines = 15;
Bitmap bitm = new Bitmap(welcome.Length * 30, (supplementaryLines + dataGridView1.Rows.Count) * lineHeight);
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
using (Graphics graphic = Graphics.FromImage(bitm))
{
int startX = 0;
int startY = 0;
int offsetY = 0;
Font newfont2 = null;
Font itemFont = null;
SolidBrush black = null;
SolidBrush white = null;
try
{
//Font newfont = new Font("Arial Black", 8);
newfont2 = new Font("Calibri", 11);
itemFont = new Font("Calibri", 11);
black = new SolidBrush(Color.Black);
white = new SolidBrush(Color.White);
//PointF point = new PointF(40f, 2f);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("" + InvoiceNo + "رقم الفاتورة ", newfont2, black, startX + 150, startY + offsetY);
offsetY = offsetY + lineHeight;
//PointF pointPrice = new PointF(15f, 45f);
graphic.DrawString("" + InvoiceDate + "", newfont2, black, startX, startY + offsetY);
offsetY = offsetY + lineHeight;
offsetY = offsetY + lineHeight;
graphic.DrawString("إسم المنتج " + "الكمية " + "السعر", newfont2, black, startX + 15, startY + offsetY);
offsetY = offsetY + lineHeight;
offsetY = offsetY + lineHeight;
graphic.DrawString("--------------------------------------------------", newfont2, black, startX, startY + offsetY);
//PointF pointPname = new PointF(10f, 65f);
//PointF pointBar = new PointF(10f, 65f);
offsetY = offsetY + lineHeight;
offsetY = offsetY + lineHeight;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
int ii = 1;
ii++;
graphic.DrawString(" " + dataGridView1.Rows[i].Cells[3].Value + " " + dataGridView1.Rows[i].Cells[2].Value + " " + dataGridView1.Rows[i].Cells[1].Value + "", itemFont,
black, startX + 15, startY + offsetY);
offsetY = offsetY + lineHeight;
}
offsetY = offsetY + lineHeight;
graphic.DrawString("--------------------------------------------------", newfont2, black, startX, startY + offsetY);
offsetY = offsetY + lineHeight;
graphic.DrawString("الإجمالي :" + gross + "", newfont2, black, startX + 15, startY + offsetY);
offsetY = offsetY + lineHeight;
graphic.DrawString("الخصم :" + discount + "", newfont2, black, startX + 15, startY + offsetY);
offsetY = offsetY + lineHeight;
graphic.DrawString("الصافي :" + net + "", newfont2, black, startX + 15, startY + offsetY);
offsetY = offsetY + lineHeight;
offsetY = offsetY + lineHeight;
graphic.DrawString("--------------------------------------------------", newfont2, black, startX, startY + offsetY);
offsetY = offsetY + lineHeight;
graphic.DrawString("" + welcome + "", newfont2, black, startX, startY + offsetY);
offsetY = offsetY + lineHeight;
}
finally
{
black.Dispose();
white.Dispose();
itemFont.Dispose();
newfont2.Dispose();
}
}
using (MemoryStream Mmst = new MemoryStream())
{
bitm.Save("ms", ImageFormat.Jpeg);
pictureBox1.Image = bitm;
pictureBox1.Width = bitm.Width;
pictureBox1.Height = bitm.Height;
}
}
maintenant, comme vous pouvez le voir, j'ai imprimé le numéro de facture et les articles qui sont tirés dans la vue de la grille de données en utilisant une instruction for.
Voici comment ce code s'imprime
Maintenant, je veux créer une mise en page de la table à partir des éléments du datagridview pour ressembler à ce reçu dans l'image ci-dessous