我更新鲜(学习者),我正在进行我的测试项目,我有一些文本要打印,因为我使用了打印文档,一切正常,但最后两行总数量和总计我希望显示文本从右到左对齐,就像物品价格,金钱一样,按照惯例看到。 希望你理解,请帮忙,下面是代码
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("Welcome ", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new Point(280, 8));
e.Graphics.DrawString("company name ", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(10, 50));
e.Graphics.DrawString("Auto Center", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(10, 75));
e.Graphics.DrawString("address,", new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(10, 95));
e.Graphics.DrawString("address,", new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(10, 115));
e.Graphics.DrawString(" po box - 00000.", new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(10, 135));
e.Graphics.DrawString("GST : Owner GST Number", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(10, 155));
e.Graphics.DrawString("abc. : " + abc.Text.Trim(), new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(10, 175));
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, 195));
e.Graphics.DrawString("Sl", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(05, 210));
e.Graphics.DrawString("No.", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(05, 228));
e.Graphics.DrawString("Product Name", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(45, 210));
e.Graphics.DrawString("Amount", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(370, 228));
e.Graphics.DrawString("UOM", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(450, 210));
e.Graphics.DrawString("Quantity", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(500, 210));
e.Graphics.DrawString("Unit Price", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(575, 210));
e.Graphics.DrawString("(Rs.)", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(575, 228));
e.Graphics.DrawString("Total", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(665, 210));
e.Graphics.DrawString("(Rs.)", new Font("Arial", 9, FontStyle.Bold), Brushes.Black, new Point(665, 228));
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, 235));
int ypos = 250;
while (i < dataGridView1.Rows.Count)
{
if (ypos > e.MarginBounds.Height)
{
ypos = 250;
e.HasMorePages = true;
return;
}
numberofitemsprinted++;
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(8, ypos));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(48, ypos));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(455, ypos));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[6].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(500, ypos));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(580, ypos));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[11].FormattedValue.ToString(), new Font("Arial", 9, FontStyle.Regular), Brushes.Black, new Point(670, ypos));
i++;
ypos = ypos + 30;
}
e.Graphics.DrawString("------------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(10, ypos));
e.Graphics.DrawString("Total Quantity (Rs) : " +txtTotaQuantity.Text.Trim(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(460, ypos + 60));
e.Graphics.DrawString("Grand Total (Rs) : " + txtGrandTotal.Text.Trim(), new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(460, ypos + 80));
e.Graphics.DrawString("Amount in Words : " + txtAmountWords.Text.Trim() + " ONLY", new Font("Arial", 10, FontStyle.Bold), Brushes.Black, new Point(20, ypos + 120));
numberofitemsperpage = 0;
numberofitemsprinted = 0;
}