我想在打印机1中打印一些数据,在打印机2中打印一些数据。
public void printkot()
{
PrintDialog pd = new PrintDialog();
PrintDocument pdoc = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
Font font = new Font("Arial", 12);
PaperSize psize = new PaperSize("Custome", 314, 500);
pd.Document = pdoc;
for (int ch = 0; dataGridView1.Rows.Count > ch; ch++)
{
if (dataGridView1.Rows[ch].Cells["calkot_print"].Value.ToString() == "K1")
{
pdoc.PrinterSettings.PrinterName = "KOT";
pdoc.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
}
}
pd.Document.DefaultPageSettings.PaperSize = psize;
pdoc.DefaultPageSettings.PaperSize.Height = 500;
pdoc.DefaultPageSettings.PaperSize.Width = 314;
if (pdoc.PrinterSettings.IsValid)
{
pdoc.Print();
}
else
{
MessageBox.Show("Printer is invalid.");
}
}
private void printDocument1_PrintPage2(object sender, PrintPageEventArgs e)
{
string table_no;
table_no = lbltable.Text;
float xs = 10;
float ys = 5;
float widths = 285.0F; // max width I found through trial and error
float heights = 0F;
DataTable dtm = blu.checkbusiness();
Font drawFontArial12Bold = new Font("Arial", 12, FontStyle.Bold);
Font drawFontArial10Regular = new Font("Arial", 9, FontStyle.Regular);
Font drawFontArial10Regularsmall = new Font("Arial", 6, FontStyle.Regular);
SolidBrush drawBrush = new SolidBrush(Color.Black);
Pen drawingPen = new Pen(Color.Black, 1);
// Set format of string.
StringFormat drawFormatCenter = new StringFormat();
drawFormatCenter.Alignment = StringAlignment.Center;
StringFormat drawFormatLeft = new StringFormat();
drawFormatLeft.Alignment = StringAlignment.Near;
StringFormat drawFormatRight = new StringFormat();
drawFormatRight.Alignment = StringAlignment.Far;
StringFormat drawFormatRightlest = new StringFormat();
string business_name = dtm.Rows[0]["business_name"].ToString();
string address = dtm.Rows[0]["address"].ToString();
Graphics gra = e.Graphics;
String strDate = DateTime.Now.ToLongTimeString();
gra.DrawString(strDate, new System.Drawing.Font("Arial", 7, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 10, 60);
e.Graphics.DrawString(business_name, drawFontArial12Bold, drawBrush, new RectangleF(xs, ys, widths, heights), drawFormatCenter);
ys += e.Graphics.MeasureString(business_name, drawFontArial12Bold).Height;
e.Graphics.DrawString(address, drawFontArial10Regular, drawBrush, new RectangleF(xs, ys, widths, heights), drawFormatCenter);
ys += e.Graphics.MeasureString(address, drawFontArial10Regular).Height;
gra.DrawString("Table No::", new System.Drawing.Font("Arial", 9, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 190, 60);
gra.DrawString(table_no, new System.Drawing.Font("Arial", 9, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 250, 45);
gra.DrawLine(drawingPen, 10, 75, 309, 75);
gra.DrawString("Item", new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(System.Drawing.Color.Black), 30, 75);
gra.DrawString("Qty", new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(System.Drawing.Color.Black), 220, 75);
gra.DrawLine(drawingPen, 10, 90, 309, 90);
int y;
y = 95;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string item_name = dataGridView1.Rows[i].Cells["cal_item_name"].Value.ToString();
string quantity = dataGridView1.Rows[i].Cells["cal_qty"].Value.ToString();
if (dataGridView1.Rows[i].Cells["calkot_print"].Value.ToString() == "K2")
{
gra.DrawString(item_name.ToString(), new System.Drawing.Font("Time New Roamn", 9, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 30, y);
gra.DrawString(quantity, new System.Drawing.Font("Time New Roamn", 9, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 220, y);
y = y + 15;
}
}
int z = y + 20;
gra.DrawLine(drawingPen, 10, z, 309, z);
gra.DrawString("Description", new System.Drawing.Font("Time New Roamn", 9, FontStyle.Bold), new SolidBrush(System.Drawing.Color.Black), 10, z + 5);
gra.DrawString(txtrichbox.Text, new System.Drawing.Font("Time New Roamn", 7, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), 10, z + 20);
z = y + 20;
}