Jfisher387
Member
- Joined
- Dec 14, 2022
- Messages
- 21
- Programming Experience
- Beginner
I am trying to print a page for each item within my BindingList.
I'm all but there. but struggling to work out how to pass the item from the list without getting an error.
Below is the code I am currently at.
My error is on line 15
i get "There is no argument given that corresponds to the required parameter 'ev' of 'JB_Helper.pd_PrintPage(object, PrintPageEventArgs, JB_Helper.JobData)'
I'm all but there. but struggling to work out how to pass the item from the list without getting an error.
Below is the code I am currently at.
My error is on line 15
i get "There is no argument given that corresponds to the required parameter 'ev' of 'JB_Helper.pd_PrintPage(object, PrintPageEventArgs, JB_Helper.JobData)'
Loop for item to print:
private void btn_Print_Click(object sender, EventArgs e)
{
//Adds data from each row into a list, then apply that list to a print function
foreach ( JobData item in jobs)
{
if (PrinterSettings.InstalledPrinters.Count >= 1)
{
if (printersList.SelectedItem != null)
{
PrintDocument pd = new PrintDocument();
//pd.PrinterSettings.PrinterName = "Zebra ZP450";
pd.PrinterSettings.PrinterName = printersList.SelectedItem.ToString();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage(item));
pd.Print();
}
}
else
{
MessageBox.Show("Printer not found!");
}
}
//finally clear out the DGV and inputs if needed,await for next label to be created
label_DGV.Rows.Clear();
label_DGV.Refresh();
}
public void pd_PrintPage(object sender,PrintPageEventArgs ev, JobData job)
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Near;
Rectangle rect1 = new Rectangle();
rect1.Height = 100;
rect1.X = 100;
rect1.Y = 100;
Rectangle rect2 = new Rectangle();
rect2.Width = 200;
rect2.Height = 100;
rect2.X = 100;
rect2.Y = 150;
Rectangle rect3 = new Rectangle();
rect3.Width = 200;
rect3.Height = 100;
rect3.X = 100;
rect3.Y = 200;
//Create a font Arial with size 16
Font font = new Font("Arial", 14);
//Create a solid brush with black color
SolidBrush brush = new SolidBrush(Color.Black);
//Get the Graphics object
Graphics g = ev.Graphics;
g.DrawString("Part #: " + Convert.ToString(job.PartNumber), font, brush, rect1, sf);
g.DrawString("QTY: " + Convert.ToString(job.OrderQty), font, brush, rect2, sf);
g.DrawString("Desc./RAL: " + job.ExtDesc, font, brush, rect3, sf);
}