I am using the below code to print an image from my C# code. Can some body tell me how to pass the filePath as an argument when i assign my event handler ?
public static bool PrintImage(string filePath)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(printPage);
pd.Print();
return true;
}
private static void printPage(object o, PrintPageEventArgs e)
{
//i want to receive the file path as a paramter here.
Image i = Image.FromFile("C:\\Zapotec.bmp");
Point p = new Point(100, 100);
e.Graphics.DrawImage(i, p);
}
The simplest way is to use a lambda expression:
Or if you’ve not got a lot to do, you could even inline the whole thing: