我已经阅读了很多类似的主题,而我似乎无法想出这个主题。
在我有这样的事情之前:
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.PrinterSettings.PrinterName = photoPrinter;
pd.Print();
private void PrintPage(object sender, PrintPageEventArgs e)
{
Image i = Image.FromFile(@"C:\workspace\FullSizeRender.jpg");
Point p = new Point(0, 0);
e.Graphics.DrawImage(i, p);
}
因为很明显,硬编码要打印的文件名并不起作用。我尝试使用lambda表达式,它已经出现了类似的东西。我知道这是错的,因为首先它说我错过了一个&#34 ;;"。但是对pd.Print()的调用在哪里;现在出发?
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = photoPrinter;
pd.PrintPage += (s, eventArgs) =>
{
Image i = Image.FromFile(newFile);
Point p = new Point(0, 0);
eventArgs.Graphics.DrawImage(i, p);
}
pd.Print();
谢谢
答案 0 :(得分:2)
lambda与否,这仍然是c#。记得用分号关闭语句:
pd.PrintPage += (s, eventArgs) =>
{
Image i = Image.FromFile(newFile);
Point p = new Point(0, 0);
eventArgs.Graphics.DrawImage(i, p);
}; // <-- here