C# .Net 3.5 在添加新事件之前删除添加到 PrintDialog 的事件
C# .Net 3.5 Remove Event added to PrintDialog before add new event
当我点击按钮时 "Print" 我的表格
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog.Document.PrintPage += (pSender, pE) => PrintEvent(pSender, pE, PrintInfo);
PrintDialog.Document.Print();
}
PrintDialog
是全局变量类型System.windows.forms.PrintDialog
。当我第二次单击按钮 "Print" 时,我想在添加新的 PrintEvent 之前删除第一次单击按钮时添加的 PrintEvent。我该怎么办?
为此,您必须将 lambda 转换为方法:
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog.Document.PrintPage -= Print;
PrintDialog.Document.PrintPage += Print;
PrintDialog.Document.Print();
}
void Print(object sender, PrintPageEventArgs e)
(
//pass info
PrintEvent(sender, e, PrintInfo)
)
当我点击按钮时 "Print" 我的表格
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog.Document.PrintPage += (pSender, pE) => PrintEvent(pSender, pE, PrintInfo);
PrintDialog.Document.Print();
}
PrintDialog
是全局变量类型System.windows.forms.PrintDialog
。当我第二次单击按钮 "Print" 时,我想在添加新的 PrintEvent 之前删除第一次单击按钮时添加的 PrintEvent。我该怎么办?
为此,您必须将 lambda 转换为方法:
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog.Document.PrintPage -= Print;
PrintDialog.Document.PrintPage += Print;
PrintDialog.Document.Print();
}
void Print(object sender, PrintPageEventArgs e)
(
//pass info
PrintEvent(sender, e, PrintInfo)
)